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

if I understand you want to sort your authors for each category , well U shoul replace line 1 by this :

$sql = 'SELECT name, providers.id, catid, catagory.catagoryname FROM providers INNER JOIN catagory ON catid = catagory.id  ORDER BY providers.id GROUP BY catagory.catagoryname';

ok so then what would be my php code to output this

it would be like this one

$reponse = $bdd->query("SELECT name, providers.id, catid, catagory.catagoryname FROM providers INNER JOIN catagory ON catid = catagory.id  ORDER BY providers.id GROUP BY catagory.catagoryname";
while($donnees = $reponse->fetch( ))
echo "Provoders_id : ".$donnees['providers.id']."category".$donnees['catagory.id']."</br>";

It looks like the problem might be in your SQL statement. Do you have a description (schema) of your tables? It would help in writing the SQL statement you're looking for. You may want to check out the following links.

http://en.wikipedia.org/wiki/Join_(SQL)

*Late browser response. I can't delete it!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.