Code output needed:
Visual Output :
My sql Database 'test'
CREATE TABLE IF NOT EXISTS `menu` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(50) NOT NULL,
`link` varchar(100) NOT NULL,
`parrent_id` int(11) NOT NULL DEFAULT '0',
`status` varchar(4) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=11 ;
--
-- Dumping data for table `menu`
--
INSERT INTO `menu` (`id`, `name`, `link`, `parrent_id`, `status`) VALUES
(1, 'Home', '#home', 0, 'Show'),
(2, 'About', '#about', 0, 'Show'),
(3, 'Our services', '#service', 0, 'Show'),
(4, 'Get involved', '#getinvolved', 0, 'Show'),
(5, 'Donors', '#donors', 0, 'Show'),
(6, 'News', '#news', 0, 'Show'),
(7, 'Contact Us', '#contact', 0, 'Show'),
(8, 'Ourselves', '#ourselves', 2, 'Show'),
(9, 'Objectives', '#objectives', 2, 'Show'),
(10, 'Our Patrons', '#patrons', 2, 'Show');
My PHP CODE is Here....
<?php
$dbuser="root";
$dbpass="";
$dbname="test"; //the name of the database
$chandle = mysql_connect("localhost", $dbuser, $dbpass)
or die("Connection Failure to Database");
mysql_select_db($dbname, $chandle) or die ($dbname . " Database not found. " . $dbuser);
function menu($parrent) {
echo "<ul>";
$sql = "SELECT * from menu where parrent_id=".$parrent;
while($res = mysql_fetch_array(mysql_query($sql)))
echo "<li><a href='".$res['link']."'>".$res['name']."</a></li>";
echo "</ul>";
}
$sql = "SELECT * from menu where parrent_id =0";
echo "<ul>";
while($resnew = mysql_fetch_array(mysql_query($sql)))
{
$sql_sub = "SELECT * from menu where parrent_id=".$resnew['id'];
$count = mysql_num_rows(mysql_query($sql_sub));
if($count>0)
{
echo "<li><a href='".$resnew['link']."'>".$resnew['name']."</a>";
menu($resnew['id']);
echo "</li>";
}
else
{
echo "<li><a href='".$resnew['link']."'>".$resnew['name']."</a></li>";
}
}
echo "</ul>";
?>
Menu Tree
a. Create the table "categorylist".
b. Insert values in the "categorylist"
c. Style sheet
d. Code for menu script
This I yust coded with ORM in Kohana Framework. Perhaps it helps. If not, feel free to be inspired...
It creates a fancy structured but simple array...
Try this query this is called semi join
You can also provide a where condition to get the results according to your requirements here it will bring all the results if parent ids are not 0. How to use Group Concat Value use php explode function for this to work.