[thelist] help w/design of SQL query
Kelly Hallman
khallman at wrack.org
Fri Nov 15 11:23:01 CST 2002
On Fri, 15 Nov 2002, Kelly Hallman wrote:
> On Fri, 15 Nov 2002, Tom Dell'Aringa wrote:
> > Based on that I did the following code:
> >
> > $result = @mysql_query("SELECT menuitem.item , category.category FROM
> > menuitem, category WHERE (menuitem.categoryID =
> > category.categoryID)");
> >
> > $prev_cat = "";
> > $category = $row["category"];
> > $price = $row["price"];
> > $menuItem = $row["item"];
> >
> > while($row = mysql_fetch_array($result))
> > {
> > if($row[$category] != $prev_cat)
> > {
> > echo("<h2>$category:</h2>");
> > }
> >
> > echo("Item: $menuItem Price: $price<br />");
> >
> > $prev_cat = $category;
> > }
>
> Try this:
>
> $lastcat = "";
> while($row = mysql_fetch_array($result)) {
> $category = $row["category"];
> $item = $row["item"];
> $price = $row["price"];
> if ($category != $lastcat) {
> echo "Category: $category\n"; }
> print "Item: $item -- Price: $price\n";
> }
>
> Your code was setting some values before any rows were fetched. Compare
> the two and you should see the difference. Good luck!
Okay, and before that last close bracket you should also set:
$lastcat = $category;
Sorry ;)
--
Kelly Hallman
http://wrack.org/
More information about the thelist
mailing list