Ok i'm just curious to understand the problem.
Here i have described the db and function source.
Hi all i have found a bug in my db class when i use the recursion.
I try to use the adjacency list model to develop a three menu but
when i call the function in recursive way i loose data because
the value returned from the fetch seem to be empty.
I have db table like this:
table catalog
ID | Name_Category | Subcategory
1 node category 0
2 1_sub_category 1
3 2_sub_category 1
4 another_node 0
5 another_node 0
I have this db class code:
http://phpfi.com/229087
And i create an instance of such class with this code.
http://phpfi.com/229088
My problem is that i take only the fist main category, the subcategory of this node and later the function esc and doesn't print the other main category.
I have try to use the native php mysql function and the code work
then the problem is in my class.
Who can help me ?
Thanks in advance.
Debug php recursion
Moderator: General Moderators
The question is why with this banal code work and if use an oop libray seem to doesn't work ?
Can you give an idea to debug.
Can you give an idea to debug.
Code: Select all
function buildThree($parent)
{
$sql = "SELECT id, nome_categoria FROM category WHERE subcategory = {$parent}";
$rs = mysql_query($sql) or die(mysql_error());
if ($rs) {
while (list($id, $nome) = mysql_fetch_array($rs)) {
$sql2 = "SELECT id FROM category WHERE subcategory = {$id}";
$rs2 = mysql_query($sql2) or die(mysql_errno());
$total = mysql_num_rows($rs2);
if ($total) {
echo'<li><a href="#">'.$nome.'</a>'."\n\r".'<ul>'."\n\r";
buildThree($id);
echo"</ul>"."\n\r"."</li>"."\n\r";
} else {
echo'<li><a href="#">'.$nome.'</a></li>'."\n\r";
}
}
}
}