I have two tables inside a test db: information (id, menu, position, visible) pages (id, information_id, menu, position, visible, content)
with which I try to make a related navigation like so:
public (inside table information with id = 1)
- home (inside table pages with information_id = 1)
- about us (inside table pages with information_id = 1)
- work (inside table pages with information_id = 1)
cms (inside table information with id = 2)
- articles (inside table pages with information_id = 2)
- add users (inside table pages with information_id = 2)
when I query the tables in PHPMyadmin I get the result I need, but when I try to echo the result out in PHP, I don't get the wanted structured menu with subitems.
<?php
$info_set = $db->prepare("SELECT *
FROM ccms.information");
$info_set->execute();
while ($information = $info_set->fetch(PDO::FETCH_ASSOC)) {
echo "<li>" . $information["menu"] . "</li>";
$page_set = $db->prepare("SELECT i.*,p.*
FROM information i
JOIN pages p
ON i.id = p.information_id");
$page_set->execute();
echo "<ul>";
while ($pages = $page_set->fetch(PDO::FETCH_ASSOC)) {
echo "<li>" . $pages["menu"] . "</li>";
}
echo "</ul>";
}
?>
The result is that the menu items from information table get echo`ed out fine, but the subitems aren't. What Am I missing here?
I apologize to everyone offended by the perhaps simplistic nature of my question, I am a novice to PHP & SQL.