Here's the plan: to create a dining guide that, among other things, allows you to edit the Cuisine types that a restaurant serves. The data is pulled from 3 tables: dining_restaurants (holds the restaurant_id among other things), dining_cuisine (holds the cuisine_id, cuisine_name and parent_id), and dining_cuisine_link (holds cuisine_link_id, cuisine_id and restaurant_id).
An example would be main category American, with sub-categories BBQ, New American, Deli, etc.
So here's the code work so far:
//Cuisine Table
$frm->freerow("<B>Cuisine Type(s):</b>","");
//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
if($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_id]){
$cuisine_html.=" checked";
}
$cuisine_html.=">$row_cuisine_sub[cuisine_name]<BR>";
}
}
What's being selected: every sub-category and NO main categories.
What exists in the DB for that restaurant_id: 2 main categories should be selected, ONLY.
I am not a coder; as it was, it took me a long time to get this code. 🙂 I also haven't done SQL in a while. I'd like to clean this up - I'm thinking it requires joining tables.
It all works, but does not select the necessary items.
Thanks,
Eve
eatley@tribweb.com