Hi all,
I am tryin to work on a new project a simple multi-level drop down menu using css and php mysql my problem is that i have written this function to get the information i need from dabase and im trying to get the levels on my sub menu to be drop down i am currently trying to follow a tutorial and this is what i have atm
function display_children($parent, $level) {
include("dbconnect.php");
$r = "SELECT a.id, a.label, a.link, Deriv1.Count FROM `menu` a LEFT OUTER JOIN (SELECT parent, COUNT(*) AS Count FROM `menu` GROUP BY parent) Deriv1 ON a.id = Deriv1.parent WHERE a.parent=".$parent."";
$result = mysqli_query($con,$r);
echo "<ul>";
while ($row = mysqli_fetch_assoc($result)) {
if ($row['Count'] > 0) {
echo "<li class='menu'><a class='list_link' href='" . $row['link'] . "'>" . $row['label'] . "</a></li>";
display_children($row['id'], $level + 1);
echo "</li>";
} elseif ($row['Count']==0) {
echo "<li><a href='" . $row['link'] . "'>" . $row['label'] . "</a></li>";
} else;
}
echo "</ul>";
}
display_children(0, 1);
HTML CODE
<style type="text/css">
.menu ul{color:#FFF;} /* Main container, includes the background of the static portion of the menu */
.menu ul li{color:#FFF;} /* This is the style for the main menu items */
.menu ul ul{color:#FFF;} /* This is the container for the first submenu */
.menu ul ul li{color:#FFF;} /* This is the style for the submenus */
</style>
and the data in database showing this on output
Home
Code
PHP
Scripts
Archive
Snippet
Help
CSS
Contact
however this is the db structure
REATE TABLE `menu` (
`id` int(11) NOT NULL auto_increment,
`label` varchar(50) NOT NULL default '',
`link` varchar(100) NOT NULL default '#',
`parent` int(11) NOT NULL default '0',
`sort` int(11) default NULL,
PRIMARY KEY (`id`),
) ENGINE=MyISAM AUTO_INCREMENT=248 DEFAULT CHARSET=latin1;
records in this table is
id label link parent sort
1 Home #home 0 0
2 Code #code 0 0
3 Contact #contact 0 0
4 PHP #php 2 0
5 CSS #css 2 0
6 Scripts #scripts 4 0
7 Help #help 4 0
8 Archive #archive 6 0
9 Snippet #snippet 8 0
So what am i doing wrong can anyone help?
Thanks,William