Way number one, much simpler here...
function categories ($id, $depth, $maxdepth) {
if ($id == 'NULL')
$query = "SELECT * FROM categories WHERE Parent IS NULL";
else
$query = "SELECT * FROM categories WHERE Parent = '" . $id . "'";
$result = mysql_query($query);
if (mysql_num_rows($result) < 1)
return;
while($row = mysql_fetch_array($result)) {
if ($depth >= $maxdepth)
break;
for ($i = 0; $i < $depth; $i++) {
echo(">> ");
}
echo($row['Name'] . "<br>");
categories ($row['ID'], ($depth + 1));
}
}
//the following starts it all
categories("NULL", 0, $maxdepth);
$maxdepth = HowManyLevelsYouWantToGoDown
Note that 0 will not display any categorie, 1 will only display the top and so on...
function categories ($id, $depth, $nrdepth, $maxdepth) {
if ($id == 'NULL')
$query = "SELECT * FROM categories WHERE Parent IS NULL";
else
$query = "SELECT * FROM categories WHERE Parent = '" . $id . "'";
$result = mysql_query($query);
if (mysql_num_rows($result) < 1)
return;
while($row = mysql_fetch_array($result)) {
if ($nrdepth > $maxdepth)
break;
categories2 ($row, $depth, $nrdepth, $maxdepth);
}
}
function categories2 ($row, $depth, $nrdepth, $maxdepth) {
echo($depth . $row['Name'] . "<br>");
$depth = $depth . $row['Name'] . " >> ";
categories ($row['ID'], $depth, ($nrdepth+1), $maxdepth);
}
//the following starts it all
categories("NULL", "", 0, $maxdepth);
$maxdepth is the same as above
Here I added numberic depth too (even though other ways may be possible).
Try this, I haven't tested it so there may well be some errors in it.
That did it! THANK-YOU SOOOO MUCH! i can't thank you enough for not giving up on me and putting up with my questions!!
I really do appreciate it!
Thank You,
Sean
No problem 😉