validation - Building a php nested lists using mysql tables -
i have 3 tables in database, join in order build 3 level nested list (which used part of menu). have far figured out how select data tables following tables:
sql tables:
page_list : pageid (primary_key) page_name pageurl
level2_menu : generalid(primary_key) gener_name pageid(foreign_key);
level3_menu : deepid(primary_key) generalid (foreign_key) deep_title
using:
<?php get_menu("select page_list.pageid pageid, page_list.page_name page_name, page_list.pageurl pageurl, level2_menu.generalid generalid, level2_menu.gener_name general_name, level3_menu.deepid deepid, level3_menu.deep_title deep_title page_list left outer join level2_menu on page_list.pageid = level2_menu.pageid left outer join level3_menu on level2_menu.generalid = level3_menu.generalid union select page_list.pageid pageid, page_list.page_name page_name, page_list.pageurl pageurl, level2_menu.generalid generalid, level2_menu.gener_name general_name, level3_menu.deepid deepid, level3_menu.deep_title deep_title page_list right outer join level2_menu on page_list.pageid = level2_menu.pageid right outer join level3_menu on level2_menu.generalid = level3_menu.generalid order pageid desc"); ?>
as getting data level 1 list , level 2 list, using:
function get_menu($sql) { include 'connect.php'; $result = $conn->query($sql); if ($result->num_rows > 0); $current_album = ""; echo "<div id='menu'><div class='menu_pos'><ul class='main-navigation'>\n"; while ($row = $result->fetch_assoc()) { if ($current_album <> "" && $current_album <> $row['pageid']) echo "</ul></li>"; if ($current_album <> $row['pageid']) { echo "<li id='qoute'><a href='#'>".$row['page_name']."</a><ul>\n"; $current_album = $row['pageid']; } if ($row['generalid'] == 'null') { echo "bob"; } else { echo "<li><a href='#'>".$row['general_name']."</a></li>\n"; } } echo "</ul></div></div>"; }
this results in the first menu example shown here 2 level list, 3 level list, second menu example, shown in jsfiddle.
Comments
Post a Comment