Hi hows it going.
I am looking to create my own forum page.
Each thread has an id, and each reply is a thread, only the difference is they have a "parent_id".
i want the code to check if the thread has any replies eg select * where parent_id = thread_id
this is all working fine. however, i want to have this recurring so that the code keep checking for EVERY reply, to see if this thread_id has any replies, so that the structure is like an endless loop, giving case or switches i think.
so a forum would look like this:
dave - 13/5/67
___reply - dave2 - 13/5/67
___reply - dave3 - 13/5/67
___reply - dave5 - 13/5/67
_______another reply - dave8 - 13/5/06
_______another reply - dave8 - 13/5/06
_____________and another reply - dave2 - 13/12/06
_______another reply - dave8 - 13/5/06
_______another reply - dave13 - 13/5/06
_____________and another reply - dave2 - 13/12/06
Can someone tell me where to start? i have looked into functions and stuff but cant seem to find they technically correct way of doing this.
need help, loops and ifs
Moderator: General Moderators
Normally what is done is the reply count is stored in the thread table. When a new post is made, this count is updated. When a post is deleted, this count is decremented.
Also, what could be done is selecting a count using a query.
Also, what could be done is selecting a count using a query.
Code: Select all
$count = mysql_query("SELECT count(*) FROM `my_table` WHERE `topicid` = '$topicid'") or die(mysql_error());
$count = mysql_result($count,0);
echo $count;Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
i understand how to cound the replies... but how do you structure it so that it indefinately will repeat the query at the end of each thread?
eg.
check for thread
---------> post thread
-------------- > check for replies
------------------> if replies > 0 post replies
----------------------->check for replies of replies
------------------------------> if replies > 0 post replies
-------------------------------->check replies of replies of replies
---------------------------------->if replies > 0 post replies
etc....
eg.
check for thread
---------> post thread
-------------- > check for replies
------------------> if replies > 0 post replies
----------------------->check for replies of replies
------------------------------> if replies > 0 post replies
-------------------------------->check replies of replies of replies
---------------------------------->if replies > 0 post replies
etc....
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
Since you've chosen to go the threaded approach to creating a forum, you may want to look into making the database structure support hierarchical trees.
http://www.sitepoint.com/print/1105
http://www.sitepoint.com/print/1105