PDA

View Full Version : Counting number of posts daily


Raakin
11-17-2015, 12:27 PM
I am trying to use this in a plugin but it keeps displaying Resource id #107 or some number instead of the actual post count.


$start = TIMENOW - 3600 * 24;

$dailypostcount = $vbulletin->db->query_read("SELECT COUNT(*) FROM " . TABLE_PREFIX . "post WHERE dateline > " . $start);


How can get the actual post count?

squidsk
11-17-2015, 02:01 PM
I am trying to use this in a plugin but it keeps displaying Resource id #107 or some number instead of the actual post count.


$start = TIMENOW - 3600 * 24;

$dailypostcount = $vbulletin->db->query_read("SELECT COUNT(*) FROM " . TABLE_PREFIX . "post WHERE dateline > " . $start);


How can get the actual post count?

The result from the a database query is not just one field, it is an array (i.e. resource) of all fields returned by the query.

To get the result from your query change the query as follows:


$start = TIMENOW - 3600 * 24;

$dailypostcount = $vbulletin->db->query_first("SELECT COUNT(*) AS postcount FROM " . TABLE_PREFIX . "post WHERE dateline > " . $start)['postcount'];

Raakin
11-17-2015, 03:14 PM
I tried this but now it doesn't even display anything.

Dave
11-17-2015, 03:22 PM
You have to use query_first if you want it to fetch the first row.

$start = TIMENOW - 3600 * 24;

$q = $vbulletin->db->query_first("SELECT COUNT(*) AS postcount FROM " . TABLE_PREFIX . "post WHERE dateline > " . $start);
$dailypostcount = $q['postcount'];

Raakin
11-17-2015, 03:50 PM
Thanks. It worked perfectly.

squidsk
11-17-2015, 05:12 PM
Sorry I thought I made that change that was my mistake. I've edited the post now to be correct.