Page 1 of 1

menu help

Posted: Mon Jul 17, 2006 5:40 pm
by benzspida
Pimptastic | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


I have a database and I am trying to write a script that will allow me display the three different catagories that are in the database.


dont know if this code is rite 

html for display menu
Sort by Menu Items
Sort by Menu Type
Sort by Price

Code: Select all

<?php

// connect to database


$conn = mysql_connect ("localhost","user","somepass")

if  (DB::isERror($db))  {die("Can't connect: " . $db->getMessage( ));  }

$db->setErrorHandling(PEAR_ERRP_DOE)'

$db->setFetchMode(DB_FETCHMODE_ASSOC):

$menuitems = $db->getAll ('SELECT menu_item,price  FROM menuitems  ORDER BY price');

$menuitems = $db->getAll ('SELECT menu_item,type  FROM menuitems  ORDER BY type');

$menuitems = $db->getAll ('SELECT menu_item,items  FROM menuitems  ORDER BY items');

if  (count($menuitems)  > 0) {

     print '<ul>';

     foreach  ($menuitems  as  %item)  {

          print "<li> $item[menu_item]  ($item[price])</li>";

          print "<li> $item[menu_item]  ($item[type])</li>";

          print "<li> $item[menu_item]  ($item[items])</li>";

     }

     print '</ul>';

}  else  {

     print 'No dishes available.';

}

?>

Pimptastic | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Re: menu help

Posted: Mon Jul 17, 2006 6:13 pm
by RobertGonzalez
benzspida wrote:I have a database and I am trying to write a script that will allow me display the three different catagories that are in the database...

html for display menu
Sort by Menu Items
Sort by Menu Type
Sort by Price

Code: Select all

<?php

// connect to database


$conn = mysql_connect ("localhost","user","somepass")

if  (DB::isERror($db))  {die("Can't connect: " . $db->getMessage( ));  }

$db->setErrorHandling(PEAR_ERRP_DOE)'

$db->setFetchMode(DB_FETCHMODE_ASSOC):

$menuitems = $db->getAll ('SELECT menu_item,price  FROM menuitems  ORDER BY price');

$menuitems = $db->getAll ('SELECT menu_item,type  FROM menuitems  ORDER BY type');

$menuitems = $db->getAll ('SELECT menu_item,items  FROM menuitems  ORDER BY items');

if  (count($menuitems)  > 0) {

     print '<ul>';

     foreach  ($menuitems  as  %item)  {

          print "<li> $item[menu_item]  ($item[price])</li>";

          print "<li> $item[menu_item]  ($item[type])</li>";

          print "<li> $item[menu_item]  ($item[items])</li>";

     }

     print '</ul>';

}  else  {

     print 'No dishes available.';

}

?>
I am n0ot sure this will give you what you want. Everytime you run a query, you are overwriting your menu items array. This will only give you a result set for the last query you ran.