Log in

View Full Version : [solved] Post Count SQL Query


omardealo
06-06-2014, 07:14 PM
HELLO ,

how i update posts count for A specific user ?

i found this code on admin/misc.php , how i can used it in plugin ?!
Or if there any Other solutions easier , To perform this jop !



$totalposts = $db->query_first("
SELECT COUNT(*) AS posts
FROM " . TABLE_PREFIX . "post AS post
INNER JOIN " . TABLE_PREFIX . "thread AS thread ON (thread.threadid = post.threadid)
WHERE post.userid = $user[userid]
AND thread.forumid IN (0$gotforums)
AND thread.visible = 1
AND post.visible = 1
");

$userdm =& datamanager_init('User', $vbulletin, ERRTYPE_CP);
$userdm->set_existing($user);
$userdm->set('posts', $totalposts['posts']);
$userdm->set_ladder_usertitle($totalposts['posts']);
$userdm->save();
unset($userdm);



Note :

i used this plug on [newpost_process] Hook
to un-visible posts if user posts Less than 5 , but when i Accept users waiting posts , count of posts not update .. so i want put Auto-update code of posts count when user put new-post



if ( $vbulletin->userinfo['posts'] <= 5 )
{
$dataman->set('visible', 0);
}

omardealo
06-08-2014, 12:59 PM
okay , i solve the problem, but i was hope to find a better solution than this ... thnx :up:


//update posts count
$totalposts = $db->query_first("
SELECT COUNT(*) AS posts
FROM " . TABLE_PREFIX . "post AS post
INNER JOIN " . TABLE_PREFIX . "thread AS thread ON (thread.threadid = post.threadid)
WHERE post.userid = '".$_POST['postuserid']."'
AND thread.visible = 1
AND post.visible = 1
");
$db->query_write("UPDATE " . TABLE_PREFIX . " user SET posts = '".$totalposts['posts']."' WHERE userid = '".$_POST['postuserid']."' ");