hii,
I am going to build menus and sub menus.I have fetch data from the table and it sucessfully display the menus and submenus..
But I have problem is that the menus displayed as un -orderd list .That menu i want to display horizontaly..
Here is the php code for that ..
.........Please Help me out..
Any help would be appriciated...
Thax..
I am going to build menus and sub menus.I have fetch data from the table and it sucessfully display the menus and submenus..
But I have problem is that the menus displayed as un -orderd list .That menu i want to display horizontaly..
Here is the php code for that ..
Code:
<?php
// include your database connection file here (if available)
// for example require_once("../../db.php");
include_once('dbconn.php');
$sql = "SELECT id, label, link_url, parent_id FROM dyn_menu ORDER BY parent_id, id ASC";
$items = mysql_query($sql);
while ($obj = mysql_fetch_object($items))
{
if ($obj->parent_id == 0) {
$parent_menu[$obj->id]['label'] = $obj->label;
$parent_menu[$obj->id]['link'] = $obj->link_url;
echo "| ";
} else {
$sub_menu[$obj->id]['parent'] = $obj->parent_id;
$sub_menu[$obj->id]['label'] = $obj->label;
$sub_menu[$obj->id]['link'] = $obj->link_url;
if (!isset($parent_menu[$obj->parent_id]['count'])) {
$parent_menu[$obj->parent_id]['count'] = 0;
}
$parent_menu[$obj->parent_id]['count']++;
}
}
mysql_free_result($items);
function dyn_menu($parent_array, $sub_array, $qs_val = "menu", $main_id = "nav", $sub_id = "subnav", $extra_style = "foldout") {
$menu = "<ul id=\"".$main_id."\"> ";
foreach ($parent_array as $pkey => $pval) {
if (!empty($pval['count'])) {
$menu .= " <li><a class=\"".$extra_style."\" href=\"".$pval['link']."?".$qs_val."=".$pkey."\">".$pval['label']."</a></li> ";
} else {
$menu .= " <li><a href=\"".$pval['link']."\">".$pval['label']."</a></li> ";
}
if (!empty($_REQUEST[$qs_val])) {
$menu .= "<ul id=\"".$sub_id."\"> ";
foreach ($sub_array as $sval) {
if ($pkey == $_REQUEST[$qs_val] && $pkey == $sval['parent']) {
$menu .= "<li><a href=\"".rebuild_link($sval['link'], $qs_val, $sval['parent'])."\" target=\"_blank\">".$sval['label']."</a></li> ";
}
}
$menu .= "</ul> ";
}
}
$menu .= "</ul>\n";
return $menu;
}
function dyn_menu_folded($parent_array, $sub_array, $qs_val = "menu", $main_id = "nav", $sub_id = "subnav", $extra_style = "foldout") {
$menu = "<ul id=\"".$main_id."\">\n";
foreach ($parent_array as $pkey => $pval) {
if (!empty($pval['count'])) {
$menu .= " <li><a class=\"".$extra_style."\" href=\"".$pval['link']."?".$qs_val."=".$pkey."\">".$pval['label']."</a></li>\n";
} else {
$menu .= " <li><a href=\"".$pval['link']."\">".$pval['label']."</a></li>\n";
}
//if (!empty($_REQUEST[$qs_val])) {
$menu .= "<ul id=\"".$sub_id."\">\n";
foreach ($sub_array as $sval) {
if ($pkey == $sval['parent']) { //
$menu .= "<li><a href=\"".$sval['link']."\" target=\"_blank\">".$sval['label']."</a></li>\n";
}
}
$menu .= "</ul>\n";
//}
}
$menu .= "</ul>\n";
return $menu;
}
function rebuild_link($link, $parent_var, $parent_val) {
$link_parts = explode("?", $link);
$base_var = "?".$parent_var."=".$parent_val;
if (!empty($link_parts[1])) {
$link_parts[1] = str_replace("&", "##", $link_parts[1]);
$parts = explode("##", $link_parts[1]);
$newParts = array();
foreach ($parts as $val) {
$val_parts = explode("=", $val);
if ($val_parts[0] != $parent_var) {
array_push($newParts, $val);
}
}
if (count($newParts) != 0) {
$qs = "&".implode("&", $newParts);
}
return $link_parts[0].$base_var.$qs;
} else {
return $link_parts[0].$base_var;
}
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Dynamic PHP navigation list example page</title>
<script type="text/javascript" src="dhtml-menu.js" language="javascript"></script>
<style type="text/css">
<!--
body {
font-family:Arial, Helvetica, sans-serif;
padding:0 15px;
}
p, li { font-size:12px;line-height:16px; }
#disply
{
width:40 px;
height:40px;
display
-->
</style>
</head>
<body>
<!--<h2>Dynamic PHP navigation list tutorial (example)</h2>
<p>The unordered list below is generated by the code used in the tutorial. Click the main items (Job groups) to make the sub-items visible.</p>
<p>We created also a second menu which shows all sub items, to get this effect we removed the code <strong>$pkey == $_REQUEST[$qs_val] && </strong> from the second <strong>foreach</strong> loop and the if statement <strong>if (!empty($_REQUEST[$qs_val]))</strong>.</p>-->
<div style="float:right;width:340px;">
<?php
//echo dyn_menu_folded($parent_menu, $sub_menu, "menu", "nav", "subnav");
?>
</div>
<?php
echo dyn_menu($parent_menu, $sub_menu, "menu", "nav", "subnav");
?>
<p style="clear:both;"></p>
</body>
</html>
.........Please Help me out..
Any help would be appriciated...
Thax..
Comment