I have 2 queries in PHP/MYSQL. I want to return results from table 1 (practice) and more than one category from table 2 (gpcats). There is a one to many relationship between Practice and GPcats. My queries return all the results from table 1 (practice) , then all the results from table 2 (gpcats). The 2 queries are not linked and the results from table 2 are not linked to the results from table 1. How do I link the two queries?
<?php
mysql_connect ("localhost", "root", "******");
mysql_select_db ('good_practice');
$region=$POST["region"];
$search=$POST["search"];
$result1 = mysql_query("SELECT * FROM practice AS p, project AS t
WHERE p.id = t.id");
$result2 = mysql_query("SELECT gpcatdesc FROM def_gpcats AS d, gpcats AS g, practice AS p
WHERE p.gpid = g.gpid AND g.gpcatid = d.gpcatid");
if(mysql_num_rows($result1)>0)
while($r=mysql_fetch_array($result1))
{
$id=$r["id"];
$min_age=$r["min_age"];
$max_age=$r["max_age"];
$gptext=$r["gptext"];
$verified=$r["verified"];
$org=$r["org"];
echo "<br><hr><br><i>Project: </i><b>$org</b><br><i>Age Range:</i> $min_age to $max_age<br> <i>Good Practice Example:</i>
<br>$gptext<br> <i>Updated:</i> $verified<br><i>Categories: <br>";
while($r=mysql_fetch_array($result2))
{ $gpcatdesc=$r["gpcatdesc"];
echo "$gpcatdesc <br>";
}
}
else {echo "Sorry, no results found ";
}
?>