For my tree category I use the below code, but there seems to be a problem, since it returns only the value of the 1st row:
<?php
function display_children($parent, $level) {
$result = mysql_query("SELECT * FROM `category` WHERE `parent`='$parent'");
while ($row = mysql_fetch_array($result)) {
$title = $row['title'];
$id = $row['id'];
$results .= str_repeat('-> ',$level).$title;
display_children($id, $level+1);
}
return $results;
}
display_children(0,0);
?>
Any ideas what am I doing wrong and how to fix this?
queryinside a loop, or even worse, inside a recursive function. There are 100 ways to do this better.