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 .. - <?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..
3 3685 Dormilich 8,658
Recognized Expert Moderator Expert
whether you display this menu horizontal or vertical is a CSS problem (because that is where you define the styling). PHP is providing only the bare content.
Im new in php mysql..I dont understand how and where should i palce the css..I tried bt nothing come out
The out put Like some as way..
Home
About Us
Contact Us
Help.
When i clik on Home ....HOme1 & Home2 appears and when click on second it hides first menus&submenus. . THis is fine, But Im confused how should i pace css here...
Please give me solution for this..
thanx...
Dormilich 8,658
Recognized Expert Moderator Expert
CSS definitions usually go into a CSS file that is included in the <head> section.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: bjaeger |
last post by:
A few months back I was "playing" with an Access 2000 application I
created. I somehow disabled the delete option from all menus,
toolbars, and context menus. Now I cannot do any maintenance on the
database because I cannot delete anything. I do not have a database
password set up, or users with security and rights. I cannot find an...
|
by: den 2005 |
last post by:
Hi everyone,
Here is code working on..Trying to insert record with a column with Image
or VarBinary datatype in sql database from a existing jpeg image file, then
retrieve this image from database and display it in a Image web control
dynamically(at runtime).
The process after being displayed in the web control, user click insert/add...
|
by: neena |
last post by:
how to display values from database tables without using datagrid control in C# .net.I want to search the values from database & the search results to be shown as rows in the web form,without the use of datagrid.So any one plz help me.
|
by: rolfejr |
last post by:
I am trying to display a PDF in the users browser that is pulled from a
binary field in our database, and keep that PDF from caching on the
client computer. I can successfully pull the PDF and display it using
the following code:
Response.ContentType = "application/pdf"
Response.BinaryWrite objRS("Attachment")
where objRS("Attachment")...
|
by: chris237 |
last post by:
The following program allows a user to select a nursery rhyme from a menu. My task is to incorporate sub-menus (nursery rhyme and fairy tales) into the program. I've tried to do this but with no success as you can see below this program. Any help with this would be greatly appreciated.
If anyone has a non-related menu program i could have a look...
| |
by: jflyingtiger |
last post by:
I am running windows xp home. I usually browse with firefox, but other browsers issue the same result. I have no background color in my sub menus, side menus, and most other portions of most web sites. In fact most web sites come up black and white with ony link highlights in blue. I believe this may have occurred after selecting and entering...
|
by: ashwani2k |
last post by:
Hello..
i develope a web projects of horoscope or astrology(http://demo.reallianzbussimart.com/allzodiac.aspx), there is an 12 Zodiaz sign and all the data call on this page through the Database , in this page i there is an one sql query ---- ...
|
by: ganesh22 |
last post by:
Hi,
my requriment is i want to display data from database in ms.word? Iam using asp.net with C#
bcoz iam inserting resume in sqlserver, so i want to display that resume in word
|
by: ieda |
last post by:
I want to display information when value in listbox selected.
Below is my code:-
This code to get value option in listbox
<?
$query = "select courseTitle from training where startDate > NOW() ";
$result = mysql_query($query);
print "<SELECT name=item>";
while ($line = mysql_fetch_array($result))
|
by: SafaaDalloul |
last post by:
Please I want know How I can Display Image from database randomly when the web page refresh in Asp.net by C# code
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |