I am using PHP to search a MySQL database
I can search multiple tables successfully but I want to display one result from one table, with multiple results from another table:
In my database one practice example has more than one category. My current PHP displays all the fields for the practice example with every relevant category. I want to display the practice example details once, then list all the categories for that practice example.
Can anyone help with how to do this?
Here is my php so far:
<?php
mysql_connect ("localhost", "root", "purple1");
mysql_select_db ('good_practice');
$search=$_POST["search"];
$result = mysql_query("SELECT * FROM practice AS p, gpcats AS g, def_gpcats AS d WHERE p.gpid = g.gpid
AND g.gpcatid = d.gpcatid");
if(mysql_num_rows($result)>0)
while($r=mysql_fetch_array($result))
{
$id=$r["id"];
$min_age=$r["min_age"];
$max_age=$r["max_age"];
$gptext=$r["gptext"];
$verified=$r["verified"];
$gpcatdesc=$r["gpcatdesc"];
echo "<b>Project ID:</B>$id<br><b>Age Range:</b> $min_age to $max_age<br> <b>Good Practice Example:</b>
<br>$gptext<br> <b>Updated:</b> $verified<br><b>Categories</b>$gpcatdesc<hr><br>";
}
else {echo "Sorry, no results found ";
}
?>