Re: tree menu from database - 3 levels
You need nested SQL statements
PHP Code:
<?php
$menu = [];
$result1 = mysql_query("SELECT * FROM table WHERE parent_id = 0");
while ($row1 = mysql_fetch_assoc($result1)) {
echo $row1['menu_title'];
$result2 = mysql_query("SELECT * FROM table WHERE parent_id = " . $row1['category_id']);
while ($row2 = mysql_fetch_assoc($result2)) {
echo '...' . $row2['menu_title'];
$result3 = mysql_query("SELECT * FROM table WHERE parent_id = " . $row2['category_id']);
while ($row3 = mysql_fetch_assoc($result3)) {
echo '......' . $row3['menu_title'];
}
}
}
?>
If the post was helpful...Rate it! Remember to use [code] or [php] tags.