Hope this helps I wrote this having read vincents reply
DB structure is where id_category is unique and auto incrementing
id_category | sub_cat_assign | cat_name
data example
1 0 accesories
2 0 lamps
3 1 hand bag
4 1 gloves
5 3 small handbags
6 0 home
you should get
accesories
-hand bags
--small handbags
-gloves
home
Hope this helps
<?php
$conID = mysql_connect ("localhost","username","password");
mysql_select_db("DATABASE", $conID);
// define spacer and call function
$space = "";
tree($conID,0,$space);
function tree($conID,$id_cat,$spacer)
{// Start of function
// select grand father ie with sub_cat_assign set to 0
$select_cat = "select id_category,
sub_cat_assign,
cat_name
from og_category
where sub_cat_assign = \"$id_cat\"";
$sub_cat_query = mysql_query($select_cat,$conID);
while ($cat_row = mysql_fetch_array($sub_cat_query))
{
$id_category = $cat_row['id_category'];
$sub_cat_assign = $cat_row['sub_cat_assign'];
$cat_name = $cat_row['cat_name'];
// Get results and echo
echo("$spacer $cat_name<br>");
// Check to see if category has any children
$check_cat_assign = "select id_category
from og_category
where sub_cat_assign = \"$id_category\"";
$check_query = mysql_query($check_cat_assign,$conID);
$check_row = mysql_num_rows($check_query);
// If cat has child then call function
if ($check_row)
{
// Add some -- to show the indenting
$space .= $spacer;
$space .= "-";
tree($conID,$id_category,$space);
}// end if $check row
}// end of while $cat row loop
} // end of function tree
?>