[thelist] php help
Tom Dell'Aringa
pixelmech at yahoo.com
Wed Nov 27 12:58:00 CST 2002
Still working on my menu thingie. Rudy was kind enough to help me
sort out my sql so I am getting the results I need. I am having
trouble with the php to display the results correctly though.
To sum up:
- The SQL pulls the results I need, which is all the items on the
menu, and each item's category.
- A couple categories have parent categories (because they are
subcategories). The 'category' table is recursive.
- I need to list my results like thus:
Category Name (Lunch)
Menu Item (burger)
Parent Category Name (Dinner)
Category Name (Specials)
Menu Item (fish)
and so on.
My SQL is:
$result = @mysql_query("
SELECT
menuitem.menuitemID,
menuitem.description,
menuitem.price,
menuitem.item,
cats.categoryName,
cats.blurb,
cats.pretext,
parentCats.categoryName,
parentCats.blurb,
parentCats.pretext
FROM
menuitem
INNER
JOIN category AS cats
on menuitem.categoryID = cats.categoryID
LEFT OUTER
JOIN category AS parentCats
on cats.parentID = parentCats.categoryID");
and my PHP following is:
$lastcat = "";
while($row = mysql_fetch_array($result))
{
$category = $row["categoryName"];
$cid = $row["categoryID"];
$blurb = $row["blurb"];
$pretext = $row["pretext"];
$item = $row["item"];
$price = $row["price"];
$desc = $row["description"];
$id = $row["menuitemID"];
$parent = $row["parentCats"];
if($category != $lastcat)
{
print "<div class='category'>$category</div>";
$lastcat = $category;
}
print "<div style='float:left; width: 75%;'
class='menuItem'>$item [<a
href='menu_item.php?mode=Edit&id=$id'>edit</a>] [<a
href='javascript: confirmDelete("$item",
$id);'>delete</a>]</div><div style='text-align: right;'>$
$price</div><div style='margin-bottom: 8px;'>$desc</div>";
}
The PHP worked before the new query, but now of course I need to list
a subcategory under a category when it has a parent. I'm a bit at a
loss where to start since PHP is fairly new to me.
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! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com
More information about the thelist
mailing list