I'm really just dipping my toes into the PHP and MySQL waters. I've made this work the way I want it to, but I know it's ugly and I'd like to know how it would be done by someone who actually knows what they're doing.
function displayCategoryMenu($db){
echo '<ul class="class">';
foreach($db->query('SELECT * FROM categoryDb, thingDb WHERE category = category AND categoryId= "aaa0001" ORDER BY category, thingName') as $row){
if($categoryName!== $row['categoryName']){
$categoryName= $row['CategoryName'];
echo '<li class="category">'.$categoryName.'</li>';
}
echo'<li><a class="fader" href="?&page='.$row['thingId']">'.$row['thingName'].'</a></li>';
}
echo '</ul>';
echo '<ul class="class">';
foreach($db->query('SELECT * FROM categoryDb, thingDb WHERE category = category AND categoryId= "aaa0002" ORDER BY category, thingName') as $row){
if($categoryName!== $row['categoryName']){
$categoryName= $row['CategoryName'];
echo '<li class="category">'.$categoryName.'</li>';
}
echo'<li><a class="fader" href="?&page='.$row['thingId']">'.$row['thingName'].'</a></li>';
}
echo '</ul>';
$db=null;
}
This basically results in an unordered list menu, where the first child acts as a header:
<ul>
<li>category1Name</li>
<li><a>thing</a></li>
<li><a>thing</a></li>
<li><a>thing</a></li>
</ul>
<ul>
<li>category2Name</li>
<li><a>thing</a></li>
<li><a>thing</a></li>
<li><a>thing</a></li>
</ul>
or:
Category1
- Thing
- Thing
- Thing
Category2
- Thing
- Thing
- Thing
and so forth...
The only difference in each ul's code is the "categoryId" (aaa0001, aaa0002, etc...) I can only imagine that I'm going about this the hard way, with the ugliest code that I can muster. I'd love to see how it should be done.