No announcement yet.

Calculating # of posts

  • Filter
  • Time
  • Show
Clear All
new posts

  • Calculating # of posts

    I am building something very similar to a message forums like this, where users post many times. I want to make visible each user's "# of posts:" in each post they make. Here is my question,
    Should I create a column in the 'users' table called 'num_posts' that increments with each post made by the user?
    :: OR ::
    Should I just run a quick query like...
    PHP Code:
    "SELECT COUNT(*) FROM posts WHERE user_id=$uid
    within the loop that prints out all the posts/threads. I am afraid this method of calculating the number of posts is processing intensive... but I dunno. What would you suggest for this? Thanks for your help! Take care.

  • #2
    If the forum software was ever used in a large installation, the query would require the entire post table to be scanned (which is an expensive operation on a large table). You should increment a postcount field in the users table that stores that information. Then whenever a user makes a post, you'd use a query like:

    UPDATE user SET postcount = postcount + 1 WHERE userid = X
    Bugdar: PHP bug tracking software that is beautiful, fast, and robust.


    widgetinstance 262 (Related Topics) skipped due to lack of content & hide_module_if_empty option.