This file builds a simple vertical menu. It runs off of a database table `tbl_menu` with fields:
menu_id (int, pk)
menu_name (varchar)
menu_id_parent (int)
menu_link (varchar)
display_page (varchar)
sort_order (int)
menu_id_parent is the menu_id one page above another.
display_page is the page to show the link on (* for all)
sort_order dictates in what order the links should appear
*Note that when inserting new pages into the table, you need to use the location relative to the root (i.e. /index.php, /users/cpanel.php, not ../foo.php or index.php)
Finally, you can use CSS to change how the menu looks.
Parent Label ("Back to: ") -> span.backlabel
Parent Link -> a.backlink
Menu Title -> span.menutitle
Menu Link -> a.menulink
By : foreignis
<?php
#First things first, connect to your database
mysql_connect("foobar.com", "foo", "bar");
mysql_select_db("foobar");
#This is the function we will use to "backtrack" to the top
function getParents($url)
{
#Find the parent for the supplied URL, if there is one.
$sql="SELECT * FROM tbl_menu ".
"WHERE menu_link='$url' ".
"AND menu_id_parent IS NOT NULL";
$result=mysql_query($sql) or die(mysql_error());
$num=mysql_num_rows($result);
#If we found a parent, good!
if ($num > 0)
{
#Get the necessary information to construct a link for the parent
$sql="SELECT * FROM tbl_menu ".
"WHERE menu_id='".mysql_result($result, 0, "menu_id_parent")."'";
$result=mysql_query($sql) or die(mysql_error());
$name=mysql_result($result, 0, "menu_name");
$url=mysql_result($result, 0, "menu_link");
#Now that we have our information, we will recursively call the getParents
#with the new URL. We do this prior to our echo for the purpose of printing
#the path in reverse order (from home down as opposed to bottom-up)
getParents($url);
#Once all the recursive calls above this one have returned, display link
echo "<span class=\"backlabel\">Back to: </span><a class=\"backlink\" href=\"$url\">$name</a><br>";
}
}
#find the current page
$current_page=$_SERVER['PHP_SELF'];
#get the path to this page, create links.
getParents($current_page);
#pull out information for this page from the database
$sql="SELECT * FROM tbl_menu WHERE menu_link='$current_page'";
$result=mysql_query($sql) or die(mysql_error());
#if we found anything, display the name of the page as the menu's title
if (mysql_num_rows($result) > 0)
{
$menu_title=mysql_result($result, 0, "menu_name");
echo "<span class=\"menutitle\">$menu_title</span>";
}
#now, get everything that isn't the current page that is set either to display on this page or on all pages (*).
$sql="SELECT * FROM tbl_menu ".
"WHERE menu_link != '$current_page' ".
"AND (display_page='$current_page' OR display_page='*') ".
"ORDER BY sort_order";
$result=mysql_query($sql) or die(mysql_error());
$num=mysql_num_rows($result);
#display a link for each row returned
for($i=0; $i<$num; $i++)
{
$url=mysql_result($result, $i, "menu_link");
$name=mysql_result($result, $i, "menu_name");
echo "<br><a class=\"menulink\" href=\"$url\">$name</a>";
}
?>
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |
More Site Navigation Code Articles
More By Codewalkers
developerWorks - FREE Tools! |
<a href="http://zeus.developershed.com/shonuff.php?blackbird=3853&zoneid=442&source=&dest=http%3A%2F%2Fwww.ibm.com%2Fdeveloperworks%2Fspaces%2Fjazz%3FS_TACT%3D105AGY31%26S_CMP%3DDEVSHED&ismap="><img src="http://images.devshed.com/corp/img/news/jazz01.gif" alt="developerWorks Jazz space" align="left"></a>You've heard the buzz about Jazz... want to know more about it from a developer's perspective? Check out the Jazz space on developerWorks. This space is an up-to-date resource for developers, including technical information about Jazz and products built on Jazz, like Rational Team Concert Express. The Jazz space includes content from a wide variety of sources, including links, feeds, and comments from experts. FREE! Go There Now!
|
|
|
|
The IBM DB2 Deep Compression ROI tool is designed for DBA’s and IT management personnel to perform a clinical analysis of the cost savings gained from the Storage Optimization feature of DB2 9 for Linux, UNIX and Windows. The feature, also known as Deep Compression, compresses data that lies within a database by up to 80% at times. FREE! Go There Now!
|
|
|
|
Hear how IBM Rational Project and Portfolio Management integrated solutions help teams put the right tools and processes in place to maximize the effectiveness and efficiency of project teams and ensure that the business vision is being executed correctly. Learn how to automate and integrate requirements prioritization, top-down project planning, communications and controls, and methodology deployment to keep your scope, costs, and schedules under control. Tackle with an end-to-end approach the management of scope and scope changes, usage of methodology to control and empower project teams, and optimization of resources to align activity costs with the overall project plan. FREE! Go There Now!
|
|
|
|
As businesses grow increasingly dependent upon Web applications to provide services to customers, employees and partners, these complex applications become more difficult to secure. Although traditional security solutions protect Internet infrastructure layers, they do not guard against HTTP and HTML attacks. Many organizations that conduct security testing still deploy applications that allow attackers to manipulate their logic and wreak havoc on their business. To mitigate this risk, development and delivery teams must address Web application security throughout the lifecycle, addressing the many layers detailed in this paper. FREE! Go There Now!
|
|
|
|
Effective governance for lean development isn’t about command and control. Instead, the focus is on enabling the right behaviors and practices through collaborative and supportive techniques. Hear from Scott Ambler on how it is far more effective to motivate people to do the right thing than it is to force them to do so. Learn how to form a lightweight, collaboration-based framework that reflects the realities of modern IT organizations. FREE! Go There Now!
|
|
|
|
Download the Rational Application Developer (RAD) v7.5 open beta code and start developing applications for the JEE5 standard which features EJB3.0, JPA, JSF 1.2, JSP 2.1 and Servlet 2.5 standards. When you use this beta you will see how you can increase developer productivity for already existing applications with improved support for refactoring, as well as adding new features to existing applications. In addition, the beta provides tooling for JD Edwards, Oracle, SAP, Siebel and PeopleSoft to improve the developer productivity with these enterprise systems. FREE! Go There Now!
|
|
|
|
Download a free trial version of IBM Rational Developer for System z, software that can help you deliver core development capabilities; the power of Java Platform, Enterprise Edition (Java EE); and rapid application development support to diverse enterprise application development teams. With comprehensive development tools to help create, deploy and maintain traditional enterprise and composite applications, Rational Developer for System z enables developers with different technical backgrounds to easily participate in important technology projects. FREE! Go There Now!
|
|
|
|
Join this Rational Talks to You teleconference on December 4 at 1:00 pm ET to discuss how Rational Method Composer can help meet your compliance objectives. Get your questions answered! FREE! Go There Now!
|
|
|
|
As organizations have grown increasingly dependent on online software, the risk of malicious attacks has also become far more serious. Fortunately, well-governed organizations can protect their Web applications by injecting vulnerability assessments and ethical hacks into their software development and delivery processes. This paper describes 12 of the most common hacker attacks and provides basic rules that you can follow to help create more hack-resistant Web applications. FREE! Go There Now!
|
|
|
|
Join this Rational Talks to You teleconference, to hear how Enterprise Generation Language (EGL) eliminates the need for tedious and error-prone low level coding, so developers can focus on business requirements. EGL extends the Rational software development platform with a simplified programming language that enables developers who have little or no experience with Java, Web technologies or Service Oriented Architecture, to create enterprise-class applications and services quickly and easily. It also allows developers who may have little or no mainframe programming experience to quickly create traditional mainframe components. FREE! Go There Now!
|
|
|
|
All FREE IBM® developerWorks Tools! |