|
Help with Recursion and mysql db
Hi All,
Hoping someone can lend a hand and point me in the right direction.
I have a mysql db with table for dynamically generated menu items. I have used the sothink javascript menu's to create the look and feel.
The problem I have is with the recursive function to get the items from the db. I cannot seem to be able to get beyond the second level and anything that has a parent of a parent wil not display.
My db setup is as follows:
id
name
link
mouseover
parentid
orderid
Thanks for your thoughts and suggestions.
This is my code (ignore the stm() stuff, this is the javascript functions):
Quote: <script type="text/javascript" language="JavaScript1.2">
<!--
stm_bm(["menu2c5d",400,"","../images/blank.gif",0,"","",0,0,250,0,1000,1,0,0,""],this);
<?
$sLevelid = 0;
function outputtable($db_name, $sLevelid)
{
?>
stm_bp("p0",[1,2,0,0,2,2,0,7,100,"",-2,"",-2,50,0,0,"#ffffff","#ffffff","",3,1,1,"#00725d"]);
<?
$list_content = mysql_db_query($db_name, "SELECT * FROM menu WHERE parentid = $sLevelid ORDER BY orderid");
$numrowsCat = mysql_num_rows($list_content);
for($i=0, $j = $numrowsCat; $i<$j; $i++)
{
//
$rowCat = mysql_fetch_array($list_content);
$sName = $rowCat["name"];
$sNotes = $rowCat["mouseover"];
$sLink = $rowCat["link"];
$sParent = $rowCat["parentid"];
$sLevelid = $sLevelid+1;
?>
stm_ai("p1i0",[0,"<?=$sName?>","","",-1,-1,0,"index.php?page=<?=$sLink?>","_self","index.php?page=<?=$sLink?>","<?=$sNotes?>","","",0,0,0,"<? if($sSubTable)echo "images/arrow_r.gif" ?>","<? if($sSubTable)echo "images/arrow_r.gif" ?>",7,7,0,0,1,"#ffffff",0,"#D6EAE6",0,"","",3,3,0,0,"#ffffff","#00725d","#00725d","#00725d","bold 8pt Verdana","bold 8pt Verdana",0,0]);
<?
if ($sParent == "0")
{
outputtable($db_name, $sLevelid);
}
if ($i <= $j -2)
{
?>
stm_ai("p1i1",[6,2,"#00715a","",-1,-1,0]);
<?
}
}
?>
stm_ep();
<?
}
$dbhost = "localhost";
$dbusername = "test";
$dbpass = "test";
$dbname = "test";
$connection = mysql_connect($dbhost, $dbusername, $dbpass);
outputtable($dbname, $sLevelid);
?>
stm_em();
//-->
</script> |
|