|
Hi, I am a relative newcomer to PHP. I am trying to make a list from 2 dbs.
I would like the list to look like this:
Category 1
Item 1
Item 2
Category 2
Item 3
Item 4
So far I've been able to get these 2 results (code follows each example):
First Try:
Category 1
Item 1
Item 2
Category 2
Item 1
Item 2
Category 1
Item 3
Item 4
Category 2
Item 3
Item 4
Code for this:
$query = "SELECT * FROM test1";
$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 test1, test2 WHERE test1.ID = test2.ID_parent";
$result2 = mysql_query($query2)
or die ("Sorry, there is a problem with the web site at this time.");
while ($row2 = mysql_fetch_array($result2))
{
$item_name = "";
extract($row2);
echo "<p><b>$item_name</b></p>";
}
}
}
mysql_close($connection);
-----------------------------
Second Try:
category1
item1
category1
item2
category2
item3
category2
item4
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))
{
$category_name = "";
$item_name = "";
extract($row);
echo"<p><b>$category_name</b><br><p><b>$Item_name</b></p>";
}
mysql_close($connection);
?>
------------------
Thanks
|