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 .= "