I've got code set up display a main category of checkboxes, and their children, using SQL and pulling that info from a database.
It looks like this:
Code: Select all
<?php
//start code here to POPULATE main categories
$sql="SELECT parent_id, cuisine_id,cuisine_name
FROM dining_cuisine
WHERE parent_id is null
ORDER BY cuisine_name";
$result=$db->query($sql);
echo mysql_error();
while($row_cuisine=$result->fetchrow(2)){
$cuisine_html.="<input type="checkbox" name="cuisine[]" value="$n"";
//start code here to select MAIN categories
// $sql2="SELECT dining_cuisine_link.cuisine_link_id, dining_cuisine_link.cuisine_id, dining_cuisine_link.restaurant_id,
// dining_restaurants.restaurant_id
// FROM dining_cuisine_link, dining_restaurants
// WHERE dining_restaurants.restaurant_id=dining_cuisine_link.restaurant_id";
// $result_sub1=$db->query($sql2);
// while($row_cuisine[cuisine_link_id]){
// $cuisine_html.=" checked";
// }
$cuisine_html.=">$row_cuisine[cuisine_name]<BR>";
//start code here to POPULATE sub-categories
$sql="SELECT parent_id, cuisine_id, cuisine_name
FROM dining_cuisine
WHERE parent_id=$row_cuisine[cuisine_id]
ORDER BY cuisine_name";
$result2=$db->query($sql);
echo mysql_error();
while($row_cuisine_sub=$result2->fetchrow(2)){
$cuisine_html.=" <input type="checkbox" name="cuisine[]" value="$n"";
//start code here to select sub-categories
// if($row_cuisine_sub[$cuisine]){
// $cuisine_html.=" checked";
// }
$cuisine_html.=">$row_cuisine_sub[cuisine_name]<BR>";
}
}
?>I could use some rearranging of the code to get a better idea of how and where I need to put code to select the checkboxes from the database.