>Subject: Re: [PHP] Recursive Childs
> thanks for that, could you just explain how it should start, should i just
call the function, how does the level get determined ???
After the function ends, starting at
*********************
$conn = pg_connect("dbname=mydb user=postgres");
*********************
is an example of how to call the function. Level starts out as level 0. Each
time the function is called, it increments the value of level that was
passed to it -- therefore a child of parent = 0 is at level 1, and a child
of parent 1 is at level 2, etc. The part that initializes everything is:
*********************
$conn = pg_connect("dbname=mydb user=postgres");
$parent = 0;
$level = 0;
$currentrecord = 0;
$rowclr = "#e7e7e7";
*********************
Change $parent to something else to start at a different point in your tree.
$level can start with whatever value you want. The next part starts an HTML
document and the table, then calls the recursive function, getChildren.
getChildren calls itself recursively to build the table. When the function
emerges again at the top level, the table and html document are ended.
*********************
print("<HTML><BODY>\n");
print("<table cellspacing=\"1\" cellpadding=\"1\" width=\"100%\">\n");
print("<tr bgcolor=\"#BBBBBB\">\n");
print("<th align=\"left\">ID</th>\n");
print("<th align=\"left\">Name</th>\n");
print("<th align=\"center\">Level</th>\n");
print("</tr>\n");
getChildren($conn,$parent,$level,$currentrecord,$rowclr);
print("</TABLE>\n");
if ($currentrecord == 0)
{
print("<H3>No matches found.</H3>\n");
}
print("</BODY></HTML>\n");
*********************
That's it -- it's actually pretty simple.
- Joe
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]