Escolar Documentos
Profissional Documentos
Cultura Documentos
There are many ways in which a menu, and menu structure can be created. Here we show how to create simple, multiple level menu system with
just a single database table.
http://phpro.org/tutorials/Simple-Mysql-PHP-Menu.html 1/6
Simple Mysql PHP Menu 26/09/2014
THE CODE
With the database in place, the code to fetch the menu is rather simple and relies on references to do the hard work.
<?php
// connect to mysql
$link = mysql_connect( 'localhost', 'username', 'passw ord' );
http://phpro.org/tutorials/Simple-Mysql-PHP-Menu.html 2/6
Simple Mysql PHP Menu 26/09/2014
// if there is no parent id
if ($data['menu_parent_id'] == 0)
{
$list[ $data['menu_item_id'] ] = &$thisref;
}
else
{
$refs[ $data['menu_parent_id'] ]['children'][ $data['menu_item_id'] ] = &$thisref;
}
}
/**
*
* Create a HTML list from an array
*
* @param array $arr
* @param string $list_type
* @return string
*
*/
function create_list( $arr )
{
$html = "\n<ul>\n";
foreach ($arr as $key=>$v)
{
$html .= '<li>'.$v['menu_item_name']."</li>\n";
if (array_key_exists('children', $v))
{
$html .= "<li>";
$html .= create_list($v['children']);
$html .= "</li>\n";
}
else{}
}
$html .= "</ul>\n";
return $html;
}
?>
http://phpro.org/tutorials/Simple-Mysql-PHP-Menu.html 3/6
Simple Mysql PHP Menu 26/09/2014
DEMONSTRATION
Boats
Power Boats
Cruisers
Dinghy
Full Cabin
Half Cabin
Yachts
Cars
Sedans
Station Wagons
Utes
Big Utes
Little Utes
Trucks
Tip Trucks
Lorries
http://phpro.org/tutorials/Simple-Mysql-PHP-Menu.html 4/6
Simple Mysql PHP Menu 26/09/2014
Road Trains
Search...
Categories
Testing
Services
Tutorials
Articles
Examples
Classes
Contact
Popular Recent
SPL Autoload
25 Sep, 2014
Easter Egg
25 Sep, 2014
About Us
http://phpro.org/tutorials/Simple-Mysql-PHP-Menu.html 5/6
Simple Mysql PHP Menu 26/09/2014
Providing the best and most up to date tutorials and examples on the web. Our candidate testing service provides the best method of screen candidates to be
assured of securing the right resource for your business.
Get in Touch
Newsletter
Keep up on our alw ays evolving product features and technology. Enter your e-mail and subscribe to our new sletter.
Latest Tweet
Contact Us
Address: 1234 Street Name, City Name, United States
Email: mail@example.com
Follow Us
I w ould rather see a sermon than hear one any day. I'd rather have you w alk w ith me, than merely point the w ay. The eye is a more ready pupil than ever w as the
ear, good advice is often confusing, but example is alw ays clear.
© Copyright 2014. All Rights Reserved.
http://phpro.org/tutorials/Simple-Mysql-PHP-Menu.html 6/6