PDA

View Full Version : Re-Filling Check Boxes from a Table



kuau
09-01-2008, 05:24 PM
I am trying to use a form to edit existing records. The records have some categories associated with them which are stored in a separate category table. I need to put checkmarks next to the categories that apply but can get only one checkbox to have a check in it plus a bunch of '.'.'.. Does anyone know how to fix this? I have highlighted the code that is wrong (I think). I got it to work on the loading of the data into the tables but now need to redisplay the data that was loaded. How do I get it out and back into the checkboxes? Thanks for any assistance.


$sql = "SELECT * FROM eventcat WHERE event_id = '".$_GET['event_id']."' ";
$result_evcat = mysql_query($sql,$connection) or die("Couldn't execute $sql query. <br> mysql error: ".mysql_error());
while($row = mysql_fetch_array($result_evcat))
{ $count++;
$evcat_id = $row['cat_id'];
}
$sql = "SELECT cat_id, category FROM category ORDER BY category";
$result_cat = mysql_query($sql,$connection) or die("Couldn't execute $sql query. <br> mysql error: ".mysql_error());
$count=0;
while ($row = mysql_fetch_array($result_cat))
{
$count++; ?>
<td width="253"><input type="checkbox" name="cats[]" value="<?php echo $row['cat_id'];?>"<?php if($row['cat_id'] == $evcat_id){echo " checked";}?>> <?php echo $row['category'];?></td>';