MySQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMySQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old March 12th, 2004, 07:10 AM
dotcomma dotcomma is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: New Zealand
Posts: 20 dotcomma User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
MySql field back into array and into checked checkboxes

Hi all,
I have managed to update my DB field with an a bunch of checkboxes. This is what appears in the DB:
Holy Places, 9/04/04<br> Easter, 11/04/04<br> Christmas, 25/12/04
Now I am making an update page where all checkbox choices appear, and I would like the previous choices checked, i.e. if the user had checked boxes 1,2,3,6,7 and 11, then I would like those to be checked when I retrieve the record.
I have managed to just display the right choices on screen with a print_r command, but how do I assign the values to the checkboxes?
To make things a little clearer, here is my current code:

<?php
$rsUpdateJob = mysql_query("SELECT * FROM jobs WHERE jobid='" . $_SESSION['jobid'] . "'") or DIE("Can\'t select the job");
$Job = mysql_fetch_assoc($rsUpdateJob);
$specname = $Job['specialname'];
$specs = explode("<br> ", $specname);
// echo "<br><br>";
// print_r($specs);
foreach($specs as $k => $v) {
// $i = 0;
// print "<b>\$specs[$i] => $v.\n</b><br>";
// $i++;
//echo "<b>$v<br></b>";
//echo current($specs)."<br>";
while ( $specnames = mysql_fetch_array($rsSpecials) ) {
?>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>
<input type="checkbox" name="SpecialName[]" value="<?php echo $specnames['specialname'] . ", " . $specnames['specialdate'];?>"<?php if (($specnames['specialname'] . ", " . $specnames['specialdate'])==current($specs)) echo "checked";?>>
<td align="left">
<?php echo $specnames['specialname']?>, <?php echo $specnames['specialdate']?>
</td>
</tr>
</table>
<?php
}
$specs++;
}
?>

This code is probably a bit messy but it reflects some of my attempts, with varying results...
I have no idea how to loop through the array.
Can anyone point me in the right direction please?
Thanks,
Toine

Reply With Quote
  #2  
Old March 15th, 2004, 09:06 PM
dotcomma dotcomma is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: New Zealand
Posts: 20 dotcomma User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Simple Solution

Well, after days of trying different things, there was a very simple solution in the end: array_intersect() did the trick!
Instead of the checkboxes I am using a multiple select list because it looks cleaner.
Here's the code, if someone is interested:
PHP Code:
<?php
$rsUpdateJob 
mysql_query("SELECT * FROM jobs WHERE jobid='" $_SESSION['jobid'] . "'") or DIE("Can\'t select the job");
$Job mysql_fetch_assoc($rsUpdateJob);
$specialname $Job['specialname'];
$specials explode("<br> "$specialname);
while ( 
$specialnames mysql_fetch_array($rsSpecials) ) {
?>
                      <option value="<?php echo $specialnames ['specialname'];?>"<?php if (array_intersect ($specials$specialnames)) { print "SELECTED" ; } ?>
                      <?php echo $specialnames ['specialname'];?>
                      </option>
                      <?php
                        
}
                      
?>
                    </select>

Reply With Quote
  #3  
Old March 16th, 2004, 07:37 AM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to dhouston
Thanks for posting a followup.
__________________
Please don't PM me asking for solutions outside the scope of a thread.
Keeping all responses in a thread stands to help others who come along later,
which is after all what this forum's all about.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMySQL Development > MySql field back into array and into checked checkboxes


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway