|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
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
|
|||
|
|||
|
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 |
|
#2
|
|||
|
|||
|
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:
|
|
#3
|
||||
|
||||
|
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. |
![]() |
| Viewing: Dev Articles Community Forums > Databases > MySQL Development > MySql field back into array and into checked checkboxes |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|