Marcjon Louwersheimer wrote:

Hello friends.

I am currently trying to develop a forum system. All is going well, but I
was wondering if there woud be a way to do something that I'm already
doing that might be more efficient.

it might be worthwhile having a looking at and playing with the code of one of the many PHP based forum systems. many of the problems you have/will come accross will probably have been solved in some way already (whether its a good solution is upto you to decide!)

Currently while it's doing the WHILE loop, it performs another query for
each post, checking how many posts have there reply field set to the
post's current ID

a simple way would be to make one extra SQL call (in addition to the one for the post details) which does a count for every distinct reply_id

SELECT reply_id, COUNT(*) AS cnt FROM topic_table

and use this result for the count info instead of making a DB call for every row in the original resultset. you could load an array with the count data ala (this would be done with a loop over the mysql result):

$countData = array();
$countData[ $row['reply_id'] ] = $row['cnt'];
.. etc

and then when you loop over the actual topic data
you can get the count for the current topid by doing the following:

echo $countData[ $currentTopicId ];

-- my SQL maybe incorrect

Or maybe there's a more effective
way by getting the number of replies first. I don't really want to store
the number of replies in the database, if I can.
If I'm not being clear or I'm not using proper netiquette, I appologize,
I'm new to this (mailing lists). Any help would be appreciated!

-- PHP Database Mailing List ( To unsubscribe, visit:

Reply via email to