With the code below I am now getting the following
Category 1
Item 1
Item 2
Category 2
Item 1
Item 2
Category 1
Item 3
Item 4
Category 2
Item 3
Item 4
I think I need to do a for each or a manual iteration of query1 but how to have Items 1 and 2 only show under Category 1 and items 2 and 3 only show under category 2 is still eluding me.
Here is the new code:
------------------------------------
$catquery = mysql_query("SELECT category_id FROM dir_cat WHERE category_name = '$TITLE'");
while ($row = mysql_fetch_array($catquery))
{
extract($row);
$find = $category_id;
}
$subquery = mysql_query("SELECT category_id FROM dir_cat WHERE category_id_parent = $find");
WHILE ($row = mysql_fetch_array ($subquery))
{
extract($row);
$sub = $category_id;
$query = "SELECT * FROM dir_cat WHERE category_id_parent = $find";
$result = mysql_query($query)
or die ("Sorry, there is a problem with the web site at this time.");
while ($row = mysql_fetch_array($result))
{
$category_name = "";
extract($row);
echo"<p><b>$category_name</b><br>";
$query2 = "SELECT * FROM dir_item WHERE category_id = $sub";
$result2 = mysql_query($query2)
or die ("Sorry, there is a problem with the web site at this time.");
while ($row2 = mysql_fetch_array($result2))
{
Very hard to tell what you are doing. Maybe something like:
SELECT category_id FROM dir_cat JOIN dir_item ON dlr_cat.category_id=dlr_item.category_id WHERE dlr_cat.category_id_parent = $find ORDER BY dlr_cat.category_name,dlr_item.item_name
Then as you loop through the results, check to see if the category changes and if it does, display the category heading.
here's the code
---------------------
$query = "SELECT * FROM test1, test2 WHERE test1.ID = test2.ID_parent ORDER BY test1.category_name, test2.Item_name";
$result = mysql_query($query)
or die ("Sorry, there is a problem with the web site at this time.");
while ($row = mysql_fetch_array($result))
Bookmarks