This function must show an undefined number of nested categories and their products
I'm having troubles with the closing tags (</>) from <ul><li> tags
This is the function:
Code: Select all
function list_tree($p = 0){
$arrStr = array();
$db1 = new db_driver();
$db1->query('SELECT id, name FROM categories WHERE CatParentId ='.$p.' ORDER BY CatOrder');
if($db1->get_num_rows()>0){
if($p>0){//cuando es mayor a 0 definimos el siguiente ul
array_push($arrStr,'<ul style="display:none">');
}
while($db1->fetch_row_object()){
array_push($arrStr,'<li id="idtree_'.$db1->row->id.'" class="catnode">'.$db1->row->name);
//these are category products
//I comment the next if bacause this part is fine
/*$db2 = new db_driver();
$db2->query('SELECT products.* FROM products, prodcat WHERE products.id = prodcat.id AND prodcat.id ='.$db1->row->id.' AND products.idNOT IN (SELECT tickets.id FROM tickets, products WHERE tickets.id=products.id) ORDER BY ProdOrder');
if($db2->get_num_rows()>0){
array_push($arrStr,'<ul style="display:none">');
while($db2->fetch_row_object()){
array_push($arrStr,'<li id="id_'.$db2->row->ProdId.'" class="prodnode">"id_'.$db2->row->name.'"</li>');
}
array_push($arrStr,'</ul>');
}//fin de los productos */
array_push($arrStr,list_tree($db1->row->id))
array_push($arrStr,'</li>')
}
array_push($arrStr,'</ul>');
}
return implode('',$arrStr);
}
Thanks and sorry with my english