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]
display number of replies to a message (DATABASE QUERY)
Moderator: General Moderators
- kendall
- Forum Regular
- Posts: 852
- Joined: Tue Jul 30, 2002 10:21 am
- Location: Trinidad, West Indies
- Contact:
display number of replies to a message (DATABASE QUERY)
Last edited by kendall on Tue Jun 17, 2003 4:24 pm, edited 1 time in total.
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
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']);
}
}- kendall
- Forum Regular
- Posts: 852
- Joined: Tue Jul 30, 2002 10:21 am
- Location: Trinidad, West Indies
- Contact:
display number of replies to a message (DATABASE
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
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
- kendall
- Forum Regular
- Posts: 852
- Joined: Tue Jul 30, 2002 10:21 am
- Location: Trinidad, West Indies
- Contact:
display number of replies to a message (DATABASE Function)
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.
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.