Hello...
I'm using a lifted function from Jay Greenspan & Brad Bulger's PHP/mySQL book for my discussion. I'm using this in conjunction with Director, that requires a final format of a list of property lists...it looks like this (not really important to understand):
[[#thread_id:1,#name:"whatever"],
[#thread_id:2,#name:"Re:whatever"],
[#thread_id:3,#name:"nothing"],
[#thread_id:4,#name:"Re:nothing"]]
If a thread is a root node, parent_id=0 and the function will recur until there are no more children in the thread. Everything works fine, except I can't seem to figure out how to insert a comma (for the list of property lists) between the last of one thread's children and the next thread's root. In other words, the separating comma in the prop list above. It end up giving me this:
[[#thread_id:1,#name:"whatever"],
[#thread_id:2,#name:"Re:whatever"] <--missing comma
[#thread_id:3,#name:"nothing"],
[#thread_id:4,#name:"Re:nothing"]]
Not sure if that makes any sense whatsoever, but maybe someone will catch my drift. Here's the function:
// void display_kids ([int topic_id [, int level]])
// This function displays child topics for the topic_id given in
// the first argument, or 0 if no topic_id is supplied.
function display_kids ($topic_id=0, $level=0)
{
if (empty($topic_id)) { $topic_id = 0; }
// retrieve topic records from the MySQL database having
// this topic_id value in their parent_id column (i.e. those
// for whom this topic is the parent_topic
$query = "select topic_id, name
from posts where
parent_id = $topic_id
order by create_dt, topic_id
";
$result = safe_query($query);
while (list($r_topic_id,$r_name ) = mysql_fetch_row($result))
{
if ($level)
{
// not the first level
echo ",[#topic_id:$r_topic_id,#name:\"$r_name\"";
}
else
{
// first level
echo "[#topic_id:$r_topic_id,#name:\"$r_name\"";
}
// display any child topics of this child, at the next
// higher level
display_kids($r_topic_id, $level+1);
}
}
NOTE: the leading and trailing brackets for the list are echoed prior and after the function call