PDA

View Full Version : thread and reply count


dinozz
07-18-2002, 07:12 PM
Hello, i tried to make an hack to count the number of threads and replies of every member of my forum.
I tried to do that with the following query :

$usertherd = $DB_site->query_first("SELECT COUNT(threadid) AS total FROM thread WHERE postuserid=$post[userid] ");
$usertherdcoun = $usertherd[total];
$userpostdcoun = $post[posts] - $usertherdcoun ;
$userscann = $DB_site->query_first("SELECT COUNT(threadid) AS total FROM thread WHERE postuserid=$post[userid] AND forumid=37");
$userscann1 = $DB_site->query_first("SELECT COUNT(threadid) AS total FROM thread WHERE postuserid=$post[userid] AND forumid=20");
$userscann2 = $DB_site->query_first("SELECT COUNT(threadid) AS total FROM thread WHERE postuserid=$post[userid] AND forumid=12");
$userscanncoun = $userscann[total]+$userscann1[total]+$userscann2[total] ;

i put this in function.php below this lines:

$post[homepage]="";
$post[findposts]="";
$post[signature]="";
$onlinestatus="";
}

Now, the problem is that, when i delete a member without deleting his posts i have the following error message :

Database error in vBulletin 2.2.6:

Invalid SQL: SELECT COUNT(threadid) AS total FROM thread WHERE postuserid=
mysql error: You have an error in your SQL syntax near '' at line 1

mysql error number: 1064

help me please

thanks

iggy123
03-22-2003, 09:21 PM
yea I got that as well when it was an "unregistered" person posting.... Please help

amykhar
03-22-2003, 10:12 PM
put an if clause around the query that makes sure userid is set.

Amy

Xenon
03-23-2003, 04:20 PM
use this code:


if (intval($post['userid']) > 0) {
$usertherd = $DB_site->query_first("SELECT COUNT(threadid) AS total FROM thread WHERE postuserid=$post[userid] ");
$usertherdcoun = $usertherd[total];
$userpostdcoun = $post[posts] - $usertherdcoun ;
$userscann = $DB_site->query_first("SELECT COUNT(threadid) AS total FROM thread WHERE postuserid=$post[userid] AND forumid IN (12,20,37)");
$userscanncoun = $userscann[total]+$userscann1[total]+$userscann2[total] ;
}


but you shouldn't use this as it produces a queries per post, which will increase the showthread load a lot..