I have products in my database like this:
1 -> torch
2 -> speaker
3 -> laptop
4 -> handphone
5 -> mouse
6 -> lcd
and in edit form, id product (example : 1,3,4,5 ) have been selected, but my form didn't selected the checkbox properly. here is my code :
$selected = array(1,3,4,5);
foreach ($selected as $val)
$q=mysql_query("Select * from product");
while ($r=mysql_fetch_array($q)){
echo "<input type='checkbox' name='product[]'";
if ($r['id'] == $val) echo "checked";
echo"> $r[product]<br>";
}
the result is only id no 5 is selected, it should be 4 products selected,,,