This is probably an easy fix – but I’ve been getting A LOT of issues trying to set this up. Basically I’m trying to create a category menu for an article page. The “list” has each category and underneath that list would be each article with the same attribute.
I have two tables set up one that holds all the categories and the other which holds the news posts. Yet for some reason…only the first post shows up – not the latter…
For example:
African Animals
Lion
Elephant
Farm Animals
Pig
<?php
$STH = $DBH->query('SELECT * FROM articles_category');
while($row = $STH->fetch()) {
echo "<li>\n";
echo "<a href='' class='nav-top-item'>". $row['category'] ."</a>\n";
echo "<ul>\n";
$STH = $DBH->query('SELECT * FROM articles WHERE category="'. $row['category'] .'"');
while($row = $STH->fetch()) {
echo "<li><a href='articles/article?id=". $row['id'] ."'>". $row['title'] ."</a></li>\n";
}
echo "</ul>\n";
echo "</li>\n";
}
?>
You are loading subcategory to same array $STH, change name, and second while should have different name too -> $row_2 will help