What it does is this:
I have a table who stores my menu-items or group-names as I like to call them. The following table should be self-explaining:
CREATE TABLE `t_groups` (
`groupe_id` int(11) NOT NULL auto_increment,
`groupe_name` varchar(30) NOT NULL default '',
`groupe_parent` int(11) NOT NULL default '0',
`groupe_url` varchar(255) NOT NULL default '',
`groupe_show` tinyint(1) NOT NULL default '1',
PRIMARY KEY (`groupe_id`),
FULLTEXT KEY `groupe_navn` (`groupe_navn`)
)
I'm using a style-sheet to format the table-cells...
The following function does the dirty work:
Code: Select all
<?php
function menu_level($parent, $indent, $connection)
{
if (isset($parent))
{
$query = "SELECT * FROM t_groups WHERE group_parent = $parent AND group_show = 1 ORDER BY group_name";
}
if (!($result = @ mysql_query ($query, $connection)))
showerror();
else
{
while ($row = mysql_fetch_array($result))
{
echo "<TR>";
echo " <TD CLASS='menu' STYLE=font-size:8pt; font-family:verdana; text-align:left;'>";
echo " <a class='menu' href='index.php?page=prodliste&group=" . $row['group_id'] . "'>";
echo " <p align='left' STYLE='text-indent: $indent ; font-weight: bold'>" . $row['group_name'];
echo " </a>";
echo " </TD>";
echo "</TR>";
$sub_query = "SELECT * FROM t_groups WHERE group_parent = " . $row['group_id'] . " AND group_show = 1 LIMIT 0, 1";
if ($sub_result = @ mysql_query ($sub_query, $connection))
{
$sub_indent = $indent + 10;
menu_level($row['group_id'], $sub_indent, $connection);
}
}
}
}?>Code: Select all
<TABLE CLASS='block' STYLE="vertical-align:top">
<TR>
<TD CLASS='heading'>GROUPS
</TD>
</TR>
<?php
if (!($connection = @ mysql_pconnect ($sql_server, $sql_user, $sql_pwd)))
showerror();
if (!(mysql_select_db ($sql_db, $connection)))
showerror();
menu_level(0,0,$connection);
?>
</TABLE>