[PHP-DB] Forum Script
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. First I'll give you some background... I am using php 4 and mysql 4. I have a database setup, and I have a table set up for forum posts. I have fields for which board it was posted on and which (if any) post it was a reply to. If it wasn't a reply, that field will be left blank. For these fields, I use a unique ID system, which makes an ID based on the poster and when it was posted. Now when I display them, I make a table for the subject (head), author, last post, number of replies etc. I make it do a SELECT query and it gets the results and displays them. Now the problem I come into is with the number of replies. 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. That works fine, but it means I'm doing (up to) 21 queries per page, which I would guess is alot. I was wondering if there would be a way I could get the number of replies as a column in my first query (where I get the forum posts). 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! -- Marcjon -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Forum Script
Hello Marcjon, Sunday, March 7, 2004, 6:12:49 PM, you wrote: ML If I'm not being clear or I'm not using proper netiquette, I appologize, ML I'm new to this (mailing lists). Any help would be appreciated! Nothing wrong at all, but it'd much easier for us if you could post your MySQL tables so we can see the relationship between them and see what fields you have, etc. -- Best regards, Richard Davey http://www.phpcommunity.org/wiki/296.html -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Forum Script
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 (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php