[thelist] help w/design of SQL query

rudy r937 at interlog.com
Fri Nov 15 11:21:01 CST 2002


> Based on that I did the following code:
>
> $result = @mysql_query("SELECT menuitem.item , category.category FROM
> menuitem, category WHERE (menuitem.categoryID =
> category.categoryID)");

you need to add     ORDER BY category, item


> $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;  }

aha, so there is an array

you have a wee error, in that you're printing price when you haven't
retrieved it in the query, but you would have found that yourself, right?

also, ordinarily i would just let this slide, tom, but i know you're the
type of person to care about stuff like this, so i thought i'd point it
out...

that's not well-formed html you're echoing there

the items should be inside a <p>..</p> block

sure, it seems trivial, but that's the diligence one needs to bring to web
work

;o)




More information about the thelist mailing list