[thelist] help w/design of SQL query
Jason Bauer
jbauer at chimesnet.com
Fri Nov 15 10:14:01 CST 2002
> > what you want to do is sequence your results by category, and
> > within
> > category by item
> >
> > order by category, item
> >
> > then, when you are processing the result set, you have to detect a
> > category
> > "break" from one row to the next, and do the "new category" logic,
> > which in your case means printing out the category name
> Yep it makes sense, I just can't get my brain to translate it to sql
> and then php! Looks like I have to hit the books on SQL again, its
> been too long..thanks.
Here is the data you'll get from the properly ordered query:
ITEM CATEGORY
Cheeseburger Lunch
Hamburger Lunch
Hot Dog Lunch
French Fries Side Order
Here is the Psuedocode to display it:
$prev_cat = "";
Loop through each result
if this row's category != $prev_cat
print "<h2>$category:</h2>";
end if
print "$item<br />";
$prev_cat = $category;
End Loop
---
Jason Bauer
jbauer at chimesnet.com
Programmer/Analyst
Chimes, Inc.
More information about the thelist
mailing list