I am populating checkboxes from data that I get from a database table. My question is different from other questions on SO because I have one checkbox defined and it loops when populated from the db. So I want to check the checkboxes that contains the values that are present in another table. With the code I have, only the checkbox with the values from the last row of the table is checked. What am I doing wrong?
//this is the value I get from the other table.
$indb = "$bid,$c,$sc,$p";
$q5=mysqli_query($link,"SELECT * FROM brands_offer WHERE Brand_Id='$bid' AND Published='1' ");
while($row5 = mysqli_fetch_array($q5)){
$catid= $row5['Catg_Id'];
$subcatid= $row5['Subcatg_Id'];
$pid= $row5['Product_Id'];
//this is the value that populates the checkboxes
$vals="$bid,$catid,$subcatid,$pid";
?>
//my argument is here
<input type="checkbox" name="checkbox[]" value="<?php echo "$vals";?>" <?php if ($vals == $indb){?> checked="checked" <?php } ?>>
<?php
echo $bname;
echo " -> ";
echo $catid;
echo ", ";
echo $subcatid;
echo ", ";
echo $pid;
echo " ";
}
Aucun commentaire:
Enregistrer un commentaire