I'm showing all my articles but want to show the category title also. I'm a n00b to databases and as far as I can tell I have to use 2 queries like this:
$sql = "SELECT id,title FROM ".$dbtable['categories']." ORDER by title";
$result = $db->query($sql);
echo '<table>';
?>
<tr>
<th>Id</th>
<th>Name</th>
<th>Category</th>
<th> </th>
</tr>
<?php
while($x = $result->fetch())
{
$sql2 = "SELECT id,name,cat_id FROM ".$dbtable['articles']." WHERE cat_id='".$x['id']."'";
$result2 = $db->query($sql2);
while($y = $result2->fetch())
{
echo '<tr>';
echo '<td>'.$y[id].'</td>';
echo '<td>'.$y[name].'</td>';
echo '<td>'.$x[title].'</td>';
echo '<td><a href="admin.php?module=articles&id='.$y['id'].'">Edit</a></td>';
echo '</tr>';
}
}
echo '</table>';
Is there a better way?