I've been trying to sort this out for a while and am getting tired so once again... I call on you guys to lend a helping hand.
Basically, I have a menu on my website that is such as:
Code:
<ul>
<li>Menu Item 1</li>
<li>Menu Item 2
<ul>
<li>Sub Menu 2 - Item 1</li>
<li>Sub Menu 2 - Item 2</li>
<ul>
<li>Sub-Sub Menu 2 - Item 1</li>
<li>Sub-Sub Menu 2 - Item 2</li>
</ul>
</ul>
</li>
<li>Menu Item 3</li>
<li>Menu Item 4
<ul>
<li>Sub Menu 4 - Item 1</li>
<li>Sub Menu 4 - Item 2</li>
</ul>
</li>
</ul>
Now I have a table in my database which is built like:
Code:
#----------------------------------------------------------------------------------------#
# id | parent | text | link | protected | sort_order #
#----------------------------------------------------------------------------------------#
# 1 | 0 | Home | /index.php | 0 | 1 #
# 2 | 0 | ByLaws | /bylaws | 0 | 2 #
# 3 | 2 | Noise | /bylaws/noise | 0 | 3 #
# 4 | 3 | Fines | /bylaws/noise/fines | 0 | 4 #
#----------------------------------------------------------------------------------------#
I have some PHP code (which is below) that I have for listing out categories and sub items which is recursive but I cannot figure out how to change it around to make up the menu structure I want. :\ I mean anything is possible but after looking at it for so long one just draws blanks.
PHP Code:
function display_children($parent, $level,$prev=0) {
global $db;
$result = $db->select("SELECT * FROM `table` WHERE parent='".$parent."' ORDER BY `sort_order` ASC");
if(mysql_num_rows($result) > 0) {
echo '<ul>';
while ($row = $db->get_row($result)) {
/*for($i = 0 ; $i < $level; $i++) {
echo " ";
}
echo " ";*/
echo '<li>'.$row["text"];
display_children($row['id'], $level+1,$level);
echo '</li>';
}
echo "</ul>";
}
}
function getCatDropDown($returnID=0) {
global $db;
$result = $db->select("SELECT * FROM `table` WHERE parent='0' ORDER BY `sort_order` ASC");
//$db->print_last_error();
if(mysql_num_rows($result)) {
echo '<ul>';
while($row=$db->get_row($result)) {
echo "<li>".$row["text"]."";
display_children($row["id"],0);
echo "</li>\n";
}
echo '</ul>';
}
}
function getCatName($id) {
global $db;
$getName = $db->select("SELECT text FROM `table` WHERE id='".$id."'");
if(mysql_num_rows($getName)) {
while($row = $db->get_row($getName)) {
return $row["text"];
}
}
}