0) { $output = ""; $res = mysql_query("SELECT * FROM comments WHERE `ItemId` = '{$id}' AND `Section` = '{$table}' AND `Visible` = '1' ORDER BY `Posted` ASC"); if(mysql_num_rows($res) > 0) { while($row = mysql_fetch_array($res)) { $obj->id = $row['Id']; $obj->itemid = $row['ItemId']; $obj->name = $row['Name']; $obj->body = $row['Body']; $obj->parentid = $row['ParentId']; $obj->postdate = $row['Posted']; $obj->linecount = $row['LineCount']; $obj->children = array(); $dataset[$obj->id] = clone $obj; } foreach($dataset as $element) { if($element->parentid == 0) { $top[] = $element; } else { if(isset($dataset[$element->parentid])) { $dataset[$element->parentid]->children[] = $element; } } } foreach($top as $comment) { $output .= print_comment($comment, $table); $output .= "
"; } } else { $output = "No comments have been posted on this entry yet."; } $output .= "
Post a new comment
"; $path = "{$render_dir}/c-{$table}-{$id}.render"; file_put_contents($path, $output); mc_delete(md5($path) . md5($path . "x")); return $output; } else { return false; } } function print_comment($comment, $table) { $output = ""; if($table == "ext") { $sect = "external-news"; } elseif($table == "sites") { $sect = "related-sites"; } else { $sect = "press"; } $c_name = utf8entities(stripslashes($comment->name)); $c_date = utf8entities($comment->postdate); $c_body = nl2br(utf8entities(stripslashes($comment->body)), false); if($comment->linecount == 1) { $output .= "
id}\">
{$c_name}   {$c_body}
"; } else { $output .= "
"; } $output .= "
{$comment->id}
"; foreach($comment->children as $child) { $output .= print_comment($child, $table); } $output .= "
"; return $output; } ?>