Hey. Basically I am porting a PHP script to coldfusion (with minor mods) however the threading aspect is something I still dont fully understand. (I am trying to make a threaded commentary system.) The code is pasted below for the function. I understand most of it except mainly how $level and $comment work, and although i know its a while loop and the function keeps calling itself I dont understand however how its stopping itself and how the end ( if ($level && $comments) ) works. Could somebody please explain these two things for me?
Much Appreciated.
PHP Function:
Much Appreciated.
PHP Function:
PHP Code:
<?
function DisplayKids ($topic_id=0, $level=0)
{
$comments = 0;
$query = "select topic_id, name, author "
.", create_dt, description from px_topics where "
." parent_id = $topic_id "
." order by create_dt, topic_id "
;
#print "<p>$query</p>\n";
$result = mysql_query($query);
while (list($r_topic_id, $r_name, $r_author, $r_create_dt, $r_description)
= mysql_fetch_row($result)
)
{
if (!$level)
{
if (!$comments)
{
print "<b>Comments:</b><br>\n";
}
print "<table border=0>\n"
."<tr bgcolor=skyblue><td colspan=2 width=500>\n";
}
else
{
if (!$comments)
{
print "<ul>\n";
}
print "<li>";
}
$comments++;
if (!eregi("[a-z0-9]",$r_author)) { $r_author = "[no name]"; }
if ($r_topic_id != $topic_id)
{
?>
<a href="display_topic.phtml?topic_id=<? print $r_topic_id; ?>"><? print $r_name; ?></a> by <b><? print $r_author; ?></b>
<?
}
else
{
?>
<? print $r_name; ?> by <b><? print $r_author; ?></b>
<?
}
?>
( <? print $r_topic_id; ?> )
<?
if ($level)
{
print "<br>\n";
}
else
{
print "</td></tr>\n"
."<tr><td width=2> </td>\n"
."<td width=498>$r_description</td>\n"
."</tr></table><br>\n"
;
}
DisplayKids($r_topic_id, $level+1);
}
if ($level && $comments)
{
print "</ul>\n";
}
}
?>
Comment