PDA

View Full Version : howto display a user's post count(errors inside?)


KingPin6
12-08-2006, 10:40 PM
I wanted to display user post count and rep in a php file, I added total forum post count and total forum usercount and that worked out perfectly, when i add the user post count by supplying a userID it doesn't seem to work...

here is some sample code, sorry for the messy code, I'm trying to learn as I go :)

$username=$_REQUEST['u'];
define('CWD', (($getcwd = getcwd()) ? $getcwd : '.'));
define('THIS_SCRIPT', 'something');

require_once(CWD . '/includes/init.php');
$totalthreads = $db->query_first("SELECT COUNT(threadid) FROM " . TABLE_PREFIX . "thread");
$totalthreads = implode(",",$totalthreads);
$totalposts = $db->query_first("SELECT COUNT(postid) FROM " . TABLE_PREFIX . "post");
$totalposts = implode(",",$totalposts);
$totalusers = $db->query_first("SELECT COUNT(userid) FROM " . TABLE_PREFIX . "user");
$totalusers = implode(",",$totalusers);
$userpost = $db->query_first("SELECT posts FROM " . TABLE_PREFIX . "user WHERE username = '%s'",
mysql_real_escape_string($username));
$userpost = implode(",",$userpost);
$userrep = $db->query_first("SELECT reputation FROM " . TABLE_PREFIX . "user WHERE username = '%s'",
mysql_real_escape_string($username));
$userrep = implode(",",$userrep);
this one gives no result but no error either.

I also tryed :

require_once(CWD . '/includes/init.php');
$totalthreads = $db->query_first("SELECT COUNT(threadid) FROM vb_thread");
$totalthreads = implode(",",$totalthreads);
$totalposts = $db->query_first("SELECT COUNT(postid) FROM vb_post");
$totalposts = implode(",",$totalposts);
$totalusers = $db->query_first("SELECT COUNT(userid) FROM vb_user");
$totalusers = implode(",",$totalusers);
$userpost = $db->query_first("SELECT posts FROM vb_user WHERE username = " . $username);
$userpost = implode(",",$userpost);
$userrep = $db->query_first("SELECT reputation FROM vb_user WHERE username = " . $username );
$userrep = implode(",",$userrep);
this one gives me : Invalid SQL:
SELECT posts FROM vb_user WHERE username = KingPin;

MySQL Error : Unknown column 'KingPin' in 'where clause'
Error Number : 1054
( I know I hardcoded the table prefix but I was just removing and changing things to get it to work...)

Any help appreciated.

Edit got it :

$userpost = $db->query_first("SELECT posts FROM " . TABLE_PREFIX . "user WHERE username = '$username'");

works like a charm.