I\'m trying to build a recursive menu which would look something like this when finished, with an infinite amount of nested items:
This is my example code to build nested menu for Zurb Foundation, using recursive function in PHP. Very simple and clean.
// call the function
build_menu();
//----------------------------
// recursive function
function build_menu($parent = "", $tab=""){
$sql = "SELECT * FROM cat WHERE parent='$parent' ORDER BY category ASC";
$q = mysql_query($sql);
if (mysql_num_rows($q)) {
if (empty($parent)):
print $tab."\n";
else:
print $tab."\n";
endif;
while($d = mysql_fetch_object($q)) {
$has_child = mysql_num_rows(mysql_query("select * from cat where parent='$d->code'") );
$tag = ($has_child ? " class='has-dropdown'" : "");
$nl = ($has_child ? "\n" : "");
print $tab."\t"."- $d->category$nl";
if ($has_child) build_menu($d->code, $tab."\t");
print $tab."
\n";
}
print $tab."
\n";
}
}