ersin d commented on a Page, Parent/Child Category Tree  -  May 08, 2009

Thanks for the code but i tried my before seen this code it helpme alot

this i writed before seen your code...

<?php

$dbconn = @mysql_connect("localhost","ersin","") or die("DB ERROR");
@mysql_select_db("cats",$dbconn) or die("DB ERROR");

function childcat($id,$name){
$query = "SELECT * FROM categories WHERE parent='$id'";
$result = @mysql_query($query) or die ("Table doesn't exists!");
while($row = mysql_fetch_array($result)){
echo "

  • -$row[name]";
    $id = $row['id'];
    $name = $row['name'];
    childcat($id,$name);
    echo "";
    }
    echo "
";
}

$query = "SELECT * FROM categories WHERE parent='0'";
$result = @mysql_query($query) or die ("Table doesn't exists!");
echo "

  • ";
    while($row = mysql_fetch_array($result)){
    echo "$row[name]";
    $name = $row['name'];
    $id = $row['id'];
    childcat($id,$name);
    echo "";
    }
    echo "
";

echo "


";
?>
Uday  -  Jul 02, 2013

Hi ersin,
I am willing to fetch all the subcategories and their subcategories by passing parent category name to a MYSQL select statement.
Can you please share if you are aware about it?

Sign in to comment

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.