Code: Select all
CREATE TABLE `menu` (
`title` varchar(255) NOT NULL,
`parent` int(11) NOT NULL,
`menu_id` int(11) NOT NULL AUTO_INCREMENT,
`pagename` varchar(255) NOT NULL,
`popup` int(1) NOT NULL,
PRIMARY KEY (`menu_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=53 ;I'm now trying this approach...
Code: Select all
<?php
$sql="select root.title as root_title
, down1.title as down1_title
, down2.title as down2_title,root.menu_id as root_id
from menu as root
left outer
join menu as down1
on down1.parent = root.menu_id
left outer
join menu as down2
on down2.parent = down1.menu_id
where root.parent ='0'
order
by root_id
, down1_title
, down2_title
";
$result=mysql_query($sql) OR DIE(mysql_error());
echo "<table>";
echo "<tr><th>root_title</th><th>down1_title</th><th>down2_title</th></tr>";
while($row=mysql_fetch_assoc($result))
{
echo "<tr><td>{$row['root_title']}</td><td>{$row['down1_title']}</td><td>{$row['down2_title']}</td></tr>";
}
echo "</table>"
?>
Any ideas?