Hello, I’m new to PHP and I have come up with the following code for my navigation but I am sure there has to be an easier and more efficient way to do this. Someone please start me on the right path. Thanks
<ul>
<?php
//run the loop to get the page titles
$query = "SELECT * FROM pages ORDER BY position ASC";
$page_set = mysql_query($query);
confirm_query($page_set);
while($page = mysql_fetch_array($page_set)){
echo '<li><a href="content.php?page=' . urlencode($page['id']) . '">' . $page['page_name'] . '</a></li>';
//run sub page query to see if the ul tag is needed
$query = "SELECT * FROM sub_pages WHERE page_id = {$page['id']} ORDER BY position ASC";
$sub_page_set = mysql_query($query);
confirm_query($sub_page_set);
$sub_page = mysql_fetch_array($sub_page_set);
if ($sub_page !=''){
echo '<ul>';
}
//run the sub page loop again to display the sub page title
$query = "SELECT * FROM sub_pages WHERE page_id = {$page['id']} ORDER BY position ASC";
$sub_page_set = mysql_query($query);
confirm_query($sub_page_set);
while($sub_page = mysql_fetch_array($sub_page_set)) {
echo '<li><a href="content.php?sub_page=' . urlencode($sub_page['id']) . '">' . $sub_page['page_name'] . '</a></li>';
}
//run the sub page loop for the last time to see if the end ul tag is needed
$query = "SELECT * FROM sub_pages WHERE page_id = {$page['id']} ORDER BY position ASC";
$sub_page_set = mysql_query($query);
confirm_query($sub_page_set);
$sub_page = mysql_fetch_array($sub_page_set);
if ($sub_page !='') {
echo '</ul>';
}
}
?>
</ul>