I need to know how to sort my authors into their respective categories
I have a mysql table with the authors details and another with the categories this is my code to get the info from the tables
(i realize I spelled category wrong in my database)
$sql = 'select name, providers.id, catid, catagory.catagoryname from providers inner join catagory on catid = catagory.id';
$result = mysqli_query($link, $sql);
while($query = mysqli_fetch_array($result))
{
$providers[] = array('name' => $query['name'], 'id' => $query['id'], 'catid' => $query['catid'], 'catname' => $query['catagoryname']);
}
$sql2 = 'select catagoryname from catagory';
$result2 = mysqli_query($link, $sql2);
while($query2 = mysqli_fetch_array($result2))
{
$catnames[] = array('catname' => $query2['catagoryname']);
}
and this is my code to ouput it
<? foreach ($catnames as $catname): ?>
<? echo $catname['catname']; ?>
<? foreach ($providers as $provider): ?>
<div> <? echo $provider['id'] . ' ' . $provider['catid'] . ' ' . $provider['name']; ?>
</div>
<? endforeach ?>
<? endforeach ?>
but it just echoes the name of each category and repeats all the information in every single category
I'm new to php and mysql I could use some help
Thanks