You are here: problem with my recursive function « PHP « IT news, forums, messages
problem with my recursive function

Posted by P80 on 05/13/05 18:59

you can check it out there:
http://www.hashmysql.org/paste/viewentry.php?id=249

also here it is:
/*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

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация