Forum Moderators: coopster
In my database table I have a messageParentId that shows if this is a new message thread (id=0) or an answer to an existing message (id=zzzzz). I have managed to make a script part that goes back or forth all the way in one level, but I don't know how to make a script that gives me all subsequent answers if a message has more than one answer.
Any one know how to get me out of recursive hell?
Thanks for any help...
In my table have
newmessage = 1 or 0 for yes or no
count1 = count of new messages
uniqeid = if new message is 1 then uniqueid = count1+1
If a reply to uniqeid, then newmessage = 0 and uniqueid is same as message responded to.
Then print out message as main topic if newmessage = 1.
Then print out all messages where newmessage =0 and uniqueid is same as where newmessage is 1 and uniqueid are the same.
every message have an originId and a parentId
Oh, now I think I am beginning to understand your table design. I was wondering how you made the connection/relation of one relative message to the previous and next. So is it something like this?
messageId originId parentId
--------- -------- --------
000000001 00000000 00000003
Can you show an example similar to this that describes the table layout?
messageId originId parentId
--------- -------- --------
000000001 00000001 00000000
000000002 00000001 00000001
000000003 00000001 00000001
000000004 00000001 00000002
000000005 00000001 00000002
000000006 00000001 00000002
000000007 00000001 00000001
000000008 00000001 00000005
000000009 00000001 00000008
000000010 00000001 00000009
Explanation:
There is only one thread, and it starts with id: 000000001, messageId 2, 3 and 7 are answers to this message, and 4 ,5 and 6 are answers to id 2. 8 is an answer to 5, 9 is an answer to 8 and 10 is an answer to 9.
Was this what you wanted?
Starting with message $a
print showmessages($a);
function showmessages($id)
{
//first show the message itself
$r=mysql_fetch_array(mysql_query("SELECT * FROM messages WHERE messageId = $id"));
$out.="$r[title] $r[text]<br>";
//now we show the children by getting one at at time
$dh=mysql_query("SELECT * FROM messages WHERE parentId = $id");
while ($r=mysql_fetch_array($dh))
{
//we add these messages to our list
$out.=showmessages($r[messageId]);
}
//return this message, with all its children and grandchildren
return $out;
}