User Post Counts


First, run this in your database:
PHP Code
  1. ALTER TABLE `members` ADD `post_count` INT( 11 ) NOT NULL DEFAULT '0';

Next find:
PHP Code
  1. case 'addreply':
  2. $id = htmlspecialchars($_POST[id]);
  3. $message = htmlspecialchars($_POST[message]);
  4. $insert = mysql_query("INSERT INTO `forum_posts` (`message`, `poster`, `thr_id`) VALUES ('$message', '$logged[username]', '$id')");
  5. echo ("Thanks for your reply. <br><a href='javascript: history.go(-1)'>Go back.</a>");
  6. break;


Change to:
PHP Code
  1. case 'addreply':
  2. //Start of post count data by Zackcez
  3. $id = htmlspecialchars($_POST[id]);
  4. $message = htmlspecialchars($_POST[message]);
  5. $get_post_count = mysql_query("SELECT * FROM `members` WHERE `id` = '$logged[id]'");
  6. $post_count = mysql_fetch_array($get_post_count);
  7. $end_posts = $post_count[post_count]+1;
  8. //End of post count data by Zackcez
  9. $do = mysql_query("UPDATE `members` SET `post_count` = '$end_posts' WHERE `id` = '$logged[id]'");
  10. $insert = mysql_query("INSERT INTO `forum_posts` (`message`, `poster`, `thr_id`) VALUES ('$message', '$logged[username]', '$id')");
  11. $insert = mysql_query("INSERT INTO `members` (`post_count`) VALUES ('$end_posts')");
  12. echo ("Thanks for your reply. <br><a href='javascript: history.go(-1)'>Go back.</a>");
  13. break;

Now you have it so every reply their post count goes up one but you also want it so when you make a new thread that it goes up too, so here that is:

Find:
PHP Code
  1. case: 'addthread':

Replace it all with:
PHP Code
  1. case 'addthread':
  2. //Start of Post Count Data by Zackcez
  3. $get_post_count = mysql_query("SELECT * FROM `members` WHERE `id` = '$logged[id]'");
  4. $post_count = mysql_fetch_array($get_post_count);
  5. $end_posts = $post_count[post_count]+1;
  6. //End of Post Count Data by Zackcez
  7. $id = htmlspecialchars($_POST[id]);
  8. $query = mysql_query("SELECT * FROM `forum_thread` WHERE `id` = '$id'");
  9. $array = mysql_fetch_array($query);
  10. if ($array[locked] == Yes)
  11. {
  12. echo ("You can't post that in here.");
  13. }
  14. else
  15. {
  16. $title = htmlspecialchars($_POST[title]);
  17. $message = htmlspecialchars($_POST[message]);
  18. $insert = mysql_query("INSERT INTO `forum_thread` (`title`, `message`, `poster`, `topic_id`) VALUES ('$title', '$message', '$logged[username]', '$id')");
  19. $do = mysql_query("UPDATE `members` SET `post_count` = '$end_posts' WHERE `id` = '$logged[id]'");
  20. $insert = mysql_query("INSERT INTO `members` (`post_count`) VALUES ('$end_posts')");
  21. echo ("Your thread has been added.<br><a href='javascript: history.go(-2)'>Go back.</a>");
  22. }
  23. break;


Now just to display the data
Find:
PHP Code
  1. <tr>
  2. <td id='mains' align='center' width='120' rowspan='2'><a href=javascript:void(window.open('members.php?user=$thread[poster]','client','status=1,width=400,height=250,top=60,left=60'))>$thread[poster]</a><br>
  3. $threadavatar[title]
  4. <br>

Under that add:
PHP Code
  1. $threadavatar[post_count]
  2. <br>

Next find:
PHP Code
  1. <tr>
  2. <td id='fields' align='center' rowspan='2'>$posts[poster]
  3. <br>

Under that add:
PHP Code
  1. $postsavatar[post_count]
  2. <br>


You're done now, please comment/post errors :o
zackcez's Avatar
Author:
Views:
3,687
Rating:
Posted on Thursday 26th June 2008 at 08:24 PM
dtnet
dtnet's Avatar
It works fine for me :P
Posted on Friday 22nd February 2008 at 10:32 PM
zackcez
zackcez's Avatar
It was tested...it's working fine for me...
Posted on Thursday 21st February 2008 at 06:01 PM
new2old
new2old's Avatar
You have first made it so that it adds one post to the user, and updates the user which is good.

But then you use the INSERT INTO query which will make every member have the $end_post 's

please test the tuts before you post