I'm having a problem showing selected items as checked. The form has a number of checkboxes from which the user can select. The selection by categoryId , which is a number (1,2,3,4 etc), is recorded in the dbase along with the users id.
When the user views the form again to change their selection, I need to show which items have already been selected.
Here's what I have, but no results. Thanks in advance.
<form action="<?=$PHP_SELF?>" method="POST">
<table border="1" cellspacing="0" cellpadding="2" summary="">
<?while ($categories = $sth->fetchRow(DB_FETCHMODE_ASSOC)){
$get = $content->query("SELECT * FROM sponsors WHERE categoryid='$categories[categoryId]'");?>
<tr>
<td>
<input type="checkbox" name="cat[]" value="<?=$categories[categoryId]?>"
<?//@row represents the categoryId (1,2,3,4 etc) the user has already selected
//and is recorded in the dbase
//if the value of @row is the same as the value of the categoryId
//show that category as checked
while($row = $sub->fetchRow()){
if($categories[categoryId] == $row[0]){
echo "checked";
}
}?> ></td>
<td class="main"><?=$categories[categoryName]?></td>
</tr>
<?while ($sponsors = $get->fetchRow(DB_FETCHMODE_ASSOC)){?>
<tr>
<td> </td>
<td class="sub"><?=$sponsors[sponsorName]?></td>
</tr>
<?}
}?>
<tr>
<td colspan="2" align="center">
<input type="hidden" name="accountid" value="<?=$accountid?>">
<input type="submit" name="submit" value="Submit">
</td>
</tr>
</table>
</form>