View Single Post
Old 02-22-2009, 07:00 AM   #2 (permalink)
jlodell
The Wanderer
 
Join Date: Feb 2009
Posts: 7
Thanks: 0
jlodell is on a distinguished road
Default

Try moving the ul tag outside the loop. That should correctly render the list.
You are looping thru the items that belong in the list, the recursive call will take care of wrapping the items in the ul.
i didn't check the logic just moved the ul tag.
<code>
class Categories {
public function categories_tree($country_id='',$parent='0',$spacer ='') {
$db = new Db();
$sql = $db->query("SELECT c.*,cd.name ".
"FROM categories AS c,categories_description AS cd ".
"WHERE c.id=cd.category_id ".
"AND c.parent='$parent' ".
"AND cd.country_id='$country_id' ".
"ORDER BY c.parent,c.type,c.sortorder");
$num = $db->count_rows($sql);
$spacer .= '- ';
echo '<ul>';
while(FALSE !== ($row = $db->fetchArray($sql))){
if($num==0 || $row['parent']=='0') {
$spacer = '';
}
echo '<li><span>',
$spacer,
'<a href="productlisting.php?cid=',
$row['id'],
'">',
$row['name'],
'</a></span>';

$this->categories_tree($country_id,$row['id'],$spacer);
echo '</li>';
}
echo '</ul>';
}
}
</code>
jlodell is offline  
Reply With Quote