I’m using the following not well thought code block to retrieve categories and it’s topics.
$query1 = "SELECT * from categories";
$result = mysql_query($query1);
while ($out = mysql_fetch_assoc($result)){
//category
print '<h2>' . $out['name'] . '</h2>';
$query2 = "SELECT * from topics where fkid = $out[id]";
$result2 = mysql_query($query2);
while($top = mysql_fetch_assoc($result2)){
//topic
print $top['name'] . '<br>';
}
}
The above does the trick. I know this is not the most practical and this being the reason I ask the group.
How can I better this so it’s more practical and simple?
Just use a single query that joins the two tables.