[thelist] php/sql - getting the rows right help (still my menuitem thing)

Tom Dell'Aringa pixelmech at yahoo.com
Fri Nov 22 12:16:01 CST 2002


I think I've got it all right except how I am pulling or displaying
my result set. Quick review, I have 2 tables, menuitem which has menu
items and a categoryID in it, and category which relates to one or
more menuitems and also has a parentID in it.

If a category has a parentID, it is a subcategory (the parentID is
the id of another category).

What I want to display is:

Category (ie. Lunch)
  burger (menuitem)
Category (dinner)
  Monday (subcategory of dinner)
    Steak (menuitem)

My SQL is:

SELECT menuitem.item, menuitem.menuitemID, menuitem.description,
menuitem.price, menuitem.categoryID, category.category,
category.blurb, category.pretext, category.parentID FROM menuitem,
category WHERE (menuitem.categoryID = category.categoryID) ORDER BY
category, item

(i am pulling everything from both tables)

My PHP to show it is:

$lastcat = "";
while($row = mysql_fetch_array($result))
{
  <just declare all the vars here, ie $id = $row["menuitemID"];>

    if($category != $lastcat)
    {
      print "<div class='category'>$category";
      if($blurb){
        print ' : ('.$blurb.')';
      }
      print '</div>';
      if(isset($pretext)){
        print "<div class='pretext'>$pretext</div>";
      }
      $lastcat = $category;
    }
    print "<the information here>";
}
--

The problem is, I have 2 categories set up with parentIDs, so they
should be subcategories and (ie, monday should come up under dinner)
but instead I just get

category
 menuitem

etc.

Any ideas -- I'm guessing my PHP is wrong since I have all the
information, but maybe I'm not grouping it right in the SQL?

Tom

=====
var me = tom.pixelmech.webDeveloper();

http://www.pixelmech.com/
http://www.maccaws.com/
[Making A Commercial Case for Adopting Web Standards]

__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus – Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com



More information about the thelist mailing list