I want to output my data into a list ordered like this
<ul>
<li>[I]category name[/I]</li>
<ul>
<li>[I]category item[/I]</li>
</ul>
<li>[I]category name[/I]</li>
<ul>
<li>[I]category item[/I]</li>
</ul>
</ul>
when I try a foreach loop like this
<? $previous_catagory = null; ?>
<? foreach ($providers as $provider): ?>
<? if ($provider['catname'] !=$previous_catagory)
{
$previous_catagory = $provider['catname'];
echo '<li>' . $provider['catname'] . '</li>' ;
}
?>
<ul>
<? $previous_provider = null; ?>
<? foreach($providers as $provider): ?>
<? if($provider['name'] !=$previous_provider)
{
$previous_provider = $provider['name'];
echo '<li>';
echo '<a href=?id="' . $provider['id'] . '">';
echo $provider['name'];
echo '</a>';
echo '</li>';
}
?>
<? endforeach ?>
</ul>
<? endforeach ?>
it outputs the category title but when it makes the category items it puts all items in every category.
I just want it to output the items in that category into the ul
mysql for this is :
$sql = 'SELECT name, providers.id, catid, catagory.catagoryname
FROM providers
INNER JOIN catagory ON catid = catagory.id
ORDER BY providers.catid';
if that helps