[thelist] help w/design of SQL query

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


--- rudy <r937 at interlog.com> wrote:

> select catname, itemname
>   from items, cats
>  where items.catid = cats.id
> order by catname, itemname

Ok, so I came up with:

SELECT `menuitem`.`item` , `category`.`category`
FROM menuitem, category
WHERE menuitem.categoryID = category.categoryID
ORDER BY `menuitem`.`item`

Now this gives me the following result set:

Hot Dog                    Lunch
Hamburger                  Lunch
French Fries               Side Order
Cheeseburger               Lunch

Which is great - but how do I display them like this:

Lunch:

Hot Dog
Hamburger
Cheeseburger

Side Order:

French Fries

Basically I want to write out the category, its items, the category,
its items, until done. I'm doing this in PHP.

(maybe I didn't make this clear!) So wouldn't I have to get the
categories first? Then run a query on each category?

something like:
sql = get the COUNT of categories

for(num of categories)
 while(category has items(sql pull here?))
   display those items

Thank you, I'm confused.

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! Web Hosting - Let the expert host your site
http://webhosting.yahoo.com



More information about the thelist mailing list