Hi all,
Can anyone lend some assistance with the following menu system?
You can take a look here: http://swiftflix.server101.com/tree_menu/right_nav.php
As you can see at the moment i have got it outputting the data successfully however i want to add function to the images to the left of the title for those that are parents so that when the page first loads it only displays the top level categories eg.
Guys
Girls
Kids
Accessories
Limited Ed.
Specials
Now, when the image to the left of the category name is clicked i want it to display any subcategories under it and if that has a sub categories to do the same and so on.
It basically should resemble a tree menu i guess.
I've looked all over the web and in the forums but have not come across anything like this.
Any help greatly appreciated.
And here is the code so far:
<script language="JavaScript">
function ToggleNode(nodeObject, imgObject)
{
if(nodeObject.style.display == '' || nodeObject.style.display == 'inline')
{
nodeObject.style.display = 'none';
imgObject.src = 'plus.gif';
}
else
{
nodeObject.style.display = 'inline';
imgObject.src = 'minus.gif';
}
}
</script>
<table width="153" border="0" cellpadding="0" cellspacing="0">
<tr>
<td> </td>
</tr><td>
<?php
function menu_level($parent, $indent, $connection)
{
if (isset($parent))
{
$query = "SELECT * FROM categories WHERE catParent = $parent";
}
if (!($result = @ mysql_query ($query, $connection)))
showerror();
else
{
$counter = 0;
while ($row = mysql_fetch_array($result))
{
$query_2 = mysql_query ("SELECT * FROM categories WHERE catParent = '" . $row['catID'] . "'");
$query_4 = mysql_num_rows($query_2);
if ($query_4 == 0){
echo "<TR>";
echo " <TD CLASS='root_td' STYLE=text-align:left;'>";
echo " <a class='rightNav' href='products.php?catID=" . $row['catID'] . "'>";
echo " <p align='left' STYLE='text-indent: $indent ; font-weight: bold'>" . $row['catName'];
echo " </a>";
echo " </TD>";
echo "</TR>";
} else {
echo "<TR>";
?>
<td id="td_root_<?php echo $counter++; ?>" class="child_td">
<img id="img_root_<?php echo $counter; ?>"
onClick="ToggleNode(td_root_<?php echo $counter; ?>, img_root_<?php echo $counter; ?>)"
border="0" src="minus.gif" style="cursor:hand">
<span class='rightNav' STYLE='text-indent: <? echo $indent ?>'><? echo $row['catName'] ?></span>
<?
echo " </TD>";
echo "</TR>";
?>
<tr>
<td height="5" valign="top"><img src="images/right_nav_dash.gif" width="3" height="5"></td>
</tr>
<?
}
?>
<?
$sub_query = "SELECT * FROM categories WHERE catParent = " . $row['catID'] . " LIMIT 0, 1";
if ($sub_result = @ mysql_query ($sub_query, $connection))
{
$sub_indent = $indent + 10;
menu_level($row['catID'], $sub_indent, $connection);
}
}
}
}
?>
<TABLE CLASS='block' STYLE="vertical-align:top">
<?php
include ('inc/db_conn_open.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>
</TD>
</TR>
</TABLE>
Cheers,
micmac