I have a form that has a number of checkboxes. Upon initial submission, the values of the checked boxes are stored as one variable via "implode" and placed into my database.
In an effort to make the form editable (that is, a user can select/deselect boxes as they wish) , I've been trying to place "checked" inside the input tag for the values that are actually in the database.
But, I can't figure out how to check to see if that particular item is in the database... I've pasted the code below and indicated where I'm having a problem.
PHP Code:
$array = array('Milk', 'Eggs', 'Bread', 'Lettuce' , 'Cookies');
$query = "SELECT * FROM qtable WHERE id='$did'";
$result = @mysql_query ($query);
while($row=mysql_fetch_array($result)) {
$item=$row['items'];
$brd=$row['brand'];
$st=$row['store'];
}
foreach ($array as $item) {
if ( $item is in database) // THIS IS WHERE I'M STUCK
$chk = 'checked';
else
$chk = '';
echo "<input type='checkbox' name='$item' value='1' $chk> $item<br>";
}
Last edited by jjfletch; 07-16-2005 at 02:07 PM..
Reason: stuck on another part...
|