I'm trying to display messages on my forum recursively, each message can have answers, the id of the parent post is in parentmessageid, the problem is that it only displays post that don't have answers ie post that have parentmessageid null /* here is my table: +----+-------+-----------------+ | id | title | parentmessageid | +----+-------+-----------------+ | 1 | a | NULL | | 2 | b | NULL | | 3 | repa | 1 | +----+-------+-----------------+ as an example I only get 1 and 2 */ function DisplayThread($realparentid="") { $sql="select id,title,parentmessageid from message where parentmessageid"; if ( $realparentid !== "" ) { //Root message do not have the ParentMessageID set $sql.="=$realparentid"; } else $sql.=" IS NULL"; $sql.=" ORDER BY id ASC"; $Reply = false; //Did we find any messages $query=mysql_query($sql); while($row=mysql_fetch_array($query)){ $Reply = true; //Found at least one message $parentid=$row['0']; $title =$row['1']; $Result.="$title<br />$sql<br />$parentid<br />"; DisplayThread("$parentid"); } //Clear the statement handle mysql_free_result($query); if ($Reply) { //At least one message was processed return $Result; } else return ""; } echo DisplayThread(); thx in advance Pat ps:you can check it out there: http://www.hashmysql.org/paste/viewentry.php?id=249 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php