Chintan commented on a Page, Parent/Child Category Tree  -  Sep 16, 2010

Hey thank you so much for sharing code I was trying to build this code from last few days but i can't achieved displaying properly in dropdown upto infinite level.It works & shows subcategoris after respective parent but one can't differentiate it. Your one is perfect.
My function was as follows
<?php
function finddepth($byid)
{

//check weather category has child
//echo "**Passed Id=".$byid;
$re_query=mysql_query("SELECT
FROM categories where parent='$byid'");

$num_rows = mysql_num_rows($re_query);
//echo " Has children:".$num_rows."
";

if(mysql_num_rows($re_query) > '0')
{

while($recursive_rw=mysql_fetch_array($re_query))
{
    $p=$recursive_rw['id'];
    $catnm=$recursive_rw['category'];
    $parent=$recursive_rw['parent'];
    $pre="|_";

    if($parent=="0")
    {
?>
<option><?php echo $catnm; ?></option>
<?php   
    }
    else
    {
    echo '<option>'.$pre.$catnm.'</option>' ;
    }
    finddepth($p);

}//end while

}//end if

}//end of function
?>

<?php finddepth(0); ?>
 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.