Please take a look at the coding below, it works, but there must be a cleaner way of writing it, does any one know? What I am after is to query my database and list the results then underneath each result to query the database again and pull out the entries which include the first query… does that make sense?
<?php
$query = "SELECT *, id AS lid FROM labels ORDER BY label";
$result = mysql_query($query) or die ("Error in query: $query. " . mysql_error());
// if records present
if (mysql_num_rows($result) > 0) {
while($row = mysql_fetch_object($result)) {
echo "<b>$row->label</b><br>";
$query2 = "SELECT * FROM titles WHERE titles.label_id = $row->lid ";
$result2 = mysql_query($query2) or die ("Error in query: $query2. " . mysql_error());
// if records present
if (mysql_num_rows($result2) > 0) {
while($row2 = mysql_fetch_object($result2)) {
echo "$row2->title<br>";
}
}
echo "<br><br>";
}
}
?>