problem with my recursive function

From: Date: Fri, 13 May 2005 16:11:16 +0000
Subject: problem with my recursive function
Groups: php.general 
Request: Send a blank email to php-general+get-215149@lists.php.net to get a copy of this message
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

« previous php.general (#215149) next »