ok, i'm trying this again, but here is where i get stuck. I can not figure out the logic on how to set up the code so it can keep grabing cat_id's from the parent_id's forever. I can only figure out how to make it travers to a set number of levels.
For Example, here is a script that will pull 2 levels:
PHP Code:
<?
$result=mysql_query("select cat_id,cat_name from heirarchy where cat_id=parent_id");
$num=mysql_numrows($result)
for($i=0;$i<$num;$i++)
{
$cat_id=mysql_result($result,$i,"cat_id");
$cat_name=mysql_result($result,$i,"cat_name");
echo "$cat_name";
$result=mysql_query("select * from heirarchy where parent_id='$cat_id'");
$num=mysql_numrows($result);
for($i=0;$i<$num;$i++)
{
$cat_id=mysql_result($result,$i,"cat_id");
$cat_name=mysql_result($result,$i,"cat_name");
echo " $cat_name";
}
}
?>
If I want it to run 5 levels, .. then i have to keep repeating the second query 5 times.. each inside the one above it. The concept of infinity still baffles me.
Does this make sense? My brain just won't work like that. Is there a way to run a loop that will just keep going until there are no parent id's left?