I am creating a restaurant directory and have two tables, one named Restaurants and another named RestaurantsCuisine. I have created an array of Cuisine ID values that I store in a field called Cuisines in the Restaurants table. I then explode the Cuisine ID values and am trying to check multiple checkboxes in an edit script for the restaurant. The Cuisine IDs in the array from the Restaurants table should match with ID fields from the RestaurantsCuisine table.
I cannot get the foreach loop to work correctly. It will check one of the checkboxes, but not all of the checkboxes that need to be checked. I have tested the foreach* statement to ensure that it is pulling in each Cuisine ID and it is successful, but I just cannot get the loop to work correctly. Any help would be appreciated.
<?
$sql = "SELECT * FROM Restaurants WHERE ID = '4' ";
$Recordset = mysql_query($sql);
$RS = mysql_fetch_assoc($Recordset);
$sql1 = "SELECT * FROM RestaurantsCuisine ORDER BY CuisineType ASC";
$Recordset1 = mysql_query($sql1);
$Cuisine = $RS['Cuisine'];
$CuisineListS = explode("|", trim($Cuisine));
while ($row_Recordset1 = mysql_fetch_array($Recordset1)) {
?>
<input name="Cuisine[]" type="checkbox" value="<?php echo $row_Recordset1['ID']; ?>"<?php
foreach ($CuisineListS as $CuisineList2) {
if($CuisineList2 == $row_Recordset1['ID']) {
echo " CHECKED";
}
}
?>
<?php echo $row_Recordset1['CuisineType']; ?><br>
<? } ?>