View Full Version : How to Update Post Count for a Single User
tim330i
08-28-2008, 08:25 PM
It seems like there would be an easy way to do this. Anyone have any ideas?
Thanks in advance,
Tim
fattony69
08-28-2008, 08:33 PM
Edit the member. There is a place for post count.
tim330i
08-28-2008, 08:41 PM
Ok, but I need to know what the value should be.
Tim
Lynne
08-28-2008, 08:59 PM
If you have phpMyAdmin, a real easy way would be to go into the post table and find all posts by that user. It then tells you in the query how many rows get returned. I think if you just want to make the query, it would be something like:
SELECT count(*)
FROM `post`
WHERE `userid` =xwhere x is the userid. (That does not take into account table prefixes. It's copied straight from phpMyAdmin - except I put count(*) in the select part of the statement.)
tim330i
08-28-2008, 09:05 PM
Yes, but that doesn't take into account forums that posts don't increment the post counter. As far as I can tell that option is stored in an option bitfield, which I can't decypher in mysql.
Tim
Opserty
08-28-2008, 09:12 PM
AdminCP > Maintenance > Update Counters > Update Post Counts
READ MESSAGE GIVEN UNDER THE TITLE BEFORE YOU PROCEED
Lynne
08-28-2008, 09:14 PM
Yes, but that doesn't take into account forums that posts don't increment the post counter. As far as I can tell that option is stored in an option bitfield, which I can't decypher in mysql.
Tim
I guess you can modify the query to add something in the where statement: AND 'forumid' !=y
tim330i
08-29-2008, 01:23 AM
AdminCP > Maintenance > Update Counters > Update Post Counts
READ MESSAGE GIVEN UNDER THE TITLE BEFORE YOU PROCEED
Yes, I read that. I don't want to do this for all members, just one. I don't see why this is so complicated.
I guess you can modify the query to add something in the where statement: AND 'forumid' !=y
I guess I could do that, figure out all the IDs and use an NOT IN statement or something....I was hoping to have the SQL/code do all the work.
It seems like this shouldn't be this hard.
Tim
Dave Hawley
08-29-2008, 02:30 AM
Updating all users post counts is the best way. Should only take 1-2 minutes.
tim330i
08-29-2008, 03:25 PM
I have a feeling it is going to take a lot longer than a few min. And I have custom post counts for some users that I can't lose.
If I wanted to simply update all the users I would have just done it and not posted looking for a solution to what I thought was a simple request.
Tim
Lynne
08-29-2008, 04:03 PM
Have you tried looking at the query in the admin cp for updating the post counts and thought of just substituting the userid for this one user? (The below code is from misc.php under do=updateposts and is for 3.6.8.)
First you have to get the forums (basically only get the forumids of those that allow post counts):
$forums = $db->query_read("
SELECT forumid
FROM " . TABLE_PREFIX . "forum AS forum
WHERE (forum.options & " . $vbulletin->bf_misc_forumoptions['countposts'] . ")
");
$gotforums = '';Then you update them. You need to put in the userid where it says $user[userid] and then the forums above where it says $gotforums. I mean, this is the actual query, but I would just do it as I said above.
$totalposts = $db->query_first("
SELECT COUNT(*) AS posts FROM " . TABLE_PREFIX . "post AS post
INNER JOIN " . TABLE_PREFIX . "thread AS thread USING (threadid)
LEFT JOIN " . TABLE_PREFIX . "deletionlog AS deletionlog_t ON (deletionlog_t.primaryid = thread.threadid AND deletionlog_t.type = 'thread')
LEFT JOIN " . TABLE_PREFIX . "deletionlog AS deletionlog_p ON (deletionlog_p.primaryid = post.postid AND deletionlog_p.type = 'post')
WHERE post.userid = $user[userid] AND
thread.forumid IN (0$gotforums) AND
deletionlog_t.primaryid IS NULL AND
deletionlog_p.primaryid IS NULL
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.