[thelist] help w/design of SQL query

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


--- Jason Bauer <jbauer at chimesnet.com> wrote:

> 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

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

--------

But I only get:

Item: Price:

for each item - and no error. Somehow it doesn't see the value of
$menuItem and $price or something to that effect...anyone?

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