Page 1 of 1

display number of replies to a message (DATABASE QUERY)

Posted: Tue Jun 17, 2003 2:32 pm
by kendall
Hello,

I am developing a Message Board system in which i want to be able to display the number of replies to a message( similar to this forum)

i have a databse table with the following

postid
title
autor
msg
replyid

How is this value accessed?

Do you run it simulateaneously while selecting the message information e.g. [syntax=php]HAVING message_articles.SELECT *, SUM(REPLYID) FROM message_articles
-> WHERE message_articles.REPLYID = message_articles.POSTID
-> GROUP BY POSTID
-> HAVING message_articles.REPLYID \G[/syntax] (is use this expression to gather the information and then get the number of replies for each meassage) or is it run as a separate query to retirving message information?

Kendall[syntax=php]<?php


?>[/syntax]

Posted: Tue Jun 17, 2003 4:22 pm
by redcircle
Are reply's to reply's considered a reply to the original or to the reply?


example

original
|-reply1
| |-reply2
|-reply1

if you are doing a hierchial system you will need to use a recursive child function

Code: Select all

function get_reply_count($post_id)
{
    global $reply_count;
   $query = 'select postid from table where replyid = "'.$post_id.'";
   $result = mysql_query($query); 
   $reply_count += mysql_num_rows($result);
   while($row = mysql_fetch_array($result))
   {
      get_reply_count($row['postid']);
   }

}

display number of replies to a message (DATABASE

Posted: Tue Jun 17, 2003 4:30 pm
by kendall
Hello,

personally i want to consider a reply' s reply is in reply to the root/ original topic much the same way it is done here

Im trying to understand your script in detail however i am ab it thrown off.

however i thought an mysql statement would have done this for me

but to see if i follow...

are you saying that i need to

select all from the table
then using the id of each message
do another search to count the replies to the id of each message?


Kendall

Posted: Tue Jun 17, 2003 5:44 pm
by redcircle
correct.. this will search all the replies until the very end of the leg.

display number of replies to a message (DATABASE Function)

Posted: Wed Jun 18, 2003 10:45 am
by kendall
Oh...

I find it tiedious that you will need to do 2 queries whan you have a mysql count function that can probably sum it up.

Is that how its done for this board?

Thanks for the help.