Number of posts on forum

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
wocdam
Forum Newbie
Posts: 2
Joined: Thu Jul 14, 2005 2:55 am

Number of posts on forum

Post by wocdam »

Hi,

I run a website with a custom forum and i would like to have the number of posts made by that user shown under his name, the problem is i have a user database of over 100 000, would it be a good idea preformance wise to search that databaese 20 times on each forum pageload or does anybody know an alternative way of doing this?
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Why search 20 times?

Code: Select all

SELECT COUNT (*) FROM `table` WHERE `username`='$username'
wocdam
Forum Newbie
Posts: 2
Joined: Thu Jul 14, 2005 2:55 am

Post by wocdam »

Because i show 20 messages per page.
The code you just gave me would increase the queries, i have the forum devided into several tables, so that would require me to do even more queries. i have the number of posts made stored in the user table. the intention was to grab the number from there. and i forgot to add something i also need to grab the signiature from the user table. so the question is, is preformance wise the best way to just grab it from the usertable each time or can anyone shed some light on other possible methods.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

For each member on that page you will need to run the query again for that user. It shouldn't be a problem, alternatively, store the post count in the DB everytime a post is made or deleted. I think phpBB does just this. That way you can run a single query to select the post count for each memeber shown on the page ;)
Post Reply