is it possible to nest queries?
i want this code to go through a database and select each distinct entry in a column of a table(column=Category, table=Link_Info). When it pull eachs one of these categories, I want it to run another query for each one of the distinct values in the column.
the code below works to pull each distinct value
<?php
include("XXXXX.php");
$connection = mysql_connect($host,$user,$password)
or die ("couldn't connect to server");
$db = mysql_select_db($database,$connection)
or die ("Couldn't select database");
$query = "SELECT DISTINCT Category FROM Link_Info ORDER BY Category";
$result = mysql_query($query)
or die ("Couldn't execute query.");
/* create form containing selection list */
while ($row = mysql_fetch_array($result))
{
extract($row);
echo "$Category<BR>\n";
}
?>
and this code below will display the information that I want
<?php
include("XXXXX.php");
$connection = mysql_connect($host, $user, $password)
or die ("oops, can't reach server");
$db = mysql_select_db($database, $connection)
or die ("oops, can't reach database");
/* Display results in a table: ArtsHumanities */
$query_ArtsHumanities = "SELECT * from Link_Info WHERE Category='Arts & Humanities' ORDER BY Link_Display";
$result = mysql_query($query_ArtsHumanities)
or die ("Couldn't execute query.");
echo "<p class='categorytitle'>Arts & Humanities<a name='Arts'></a></p>";
echo "<table>";
while ($row = mysql_fetch_array($result))
{
extract($row);
echo "<tr> \n
<td><a href='$Link_URL' target='blank'>$Link_Display</a></td></tr>\n
<tr><td class='link_description'><ul><li>$Link_Description</li></td></tr></tr>\n";
echo "<tr><td></td></tr>\n";
}
echo "</table><br>\n";
I tried to combine them into the code below, but i'm not getting any results returned. all that i am seein is a blank page(except for the html that is written outside of the php).
<?php
include("XXXXX.php");
$connection = mysql_connect($host,$user,$password)
or die ("couldn't connect to server");
$db = mysql_select_db($database,$connection)
or die ("Couldn't select database");
$query = "SELECT DISTINCT Category FROM Link_Info ORDER BY Category";
$result = mysql_query($query)
or die ("Couldn't execute query.");
/* create form containing selection list */
while ($row = mysql_fetch_array($result))
{
$query_category = "SELECT * from Link_Info WHERE Category='$Category' ORDER BY Link_Display";
$result = mysql_query($query_category)
or die ("Couldn't execute query.");
echo "<p class='categorytitle'>$Category<a name='Arts'></a></p>";
echo "<table>";
while ($row = mysql_fetch_array($result))
{
extract($row);
echo "<tr> \n
<td><a href='$Link_URL' target='blank'>$Link_Display</a></td></tr>\n
<tr><td class='link_description'><ul><li>$Link_Description</li></td></tr></tr>\n";
echo "<tr><td></td></tr>\n";
}
echo "</table><br>\n";
}
?>
any ideas about why this isn't working, or better ways to do what i'm trying to do?
thanks for the help.