looping twice function
Posted: Sun Apr 04, 2010 12:52 pm
I'm trying to write a code to create a menu from a database. The code is supposed to find the 'page_name' which is the menu name and then loop through all existing "sections" of that menu (appetizers, salad, soup...), then loop through each section to find the food items.
I guess what I envision in the end is I have a 'menu' function where I can put wherever I want that section to appear. ex: menu(dinner,salad) and the dinner salad will section appears.
After a few days of going crazy over this, I think my code just stopped making sense.
I guess what I envision in the end is I have a 'menu' function where I can put wherever I want that section to appear. ex: menu(dinner,salad) and the dinner salad will section appears.
After a few days of going crazy over this, I think my code just stopped making sense.
Code: Select all
$menu_info_tbl = mysql_query("SELECT * FROM menu_info WHERE page_name='$menu_name'");
while($row = mysql_fetch_array($menu_info_tbl))
{
$section_name = $row['section_name'];
$menu_name = $row['page_name_name'];
foreach
($section_name as $section_name and $menu_name as $menu_name)
{
function create_menu($menu_name,$section_name)
{
$menu_info_tbl = mysql_query("SELECT * FROM menu_info WHERE page_name='$menu_name' AND section_name='$section_name'");
while($row = mysql_fetch_array($menu_info_tbl))
{
$food_id = $row['food_id'];
$section_name = $row['section_name'];
$page_name = $row['page_name'];
$food_name = $row['food_name'];
$food_price = $row['food_price'];
$food_description = $row['food_description'];
};
};
};
};