View Full Version : need help with vB variables or queries regarding new posts/daily posts
Slapyo
09-09-2004, 08:03 PM
i was wondering if there was a built in variable for vB that would tell you how many new posts there have been since you last visit, and how many posts there have been that day.
View New Posts (234) | Today's Posts (234)
i want something like that. now if there is a variable like $bbuserinfo or $pmbox that could give me this information that would be great. if not, could someone give me the 2 queries i would use to gather this information.
Xenon
09-09-2004, 08:55 PM
nope, there isn't such a variable, as it would produce extra queries which should be avoided
the sql would be:
SELECT COUNT(postid) AS newposts FROM post WHERE dateline > $bbuserinfo[lastvisit]
Slapyo
09-09-2004, 08:59 PM
ok cool, what about how to select for daily threads.
i'm not worried about extra queries because it is going on a non-vb page that only has a few so it won't be adding anything extra to the message board.
Slapyo
09-09-2004, 09:13 PM
i got an error when i ran this:
$countnewthreads = $DB_site->query_first('SELECT COUNT(postid) AS newposts FROM post WHERE dateline > $bbuserinfo[lastvisit]');
$totalnewthreads = number_format($countnewthreads['newposts']);
Invalid SQL: SELECT COUNT(postid) AS newposts FROM post WHERE dateline > $bbuserinfo[lastvisit]
mysql error: You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '[lastvisit]' at line 1
mysql error number: 1064
Xenon
09-09-2004, 09:24 PM
use doublequotes instead of single quotes and it will work :)
Slapyo
09-09-2004, 09:34 PM
ok that worked thanks. now what do i change in the query to make it so it gives the count for the getdaily search?
the reason i ask is i think from looking at the database the times are stored in unix_timestamp format. but i don't think php has a unix_timestamp function, just mysql.
$countnewthreads = $DB_site->query_first('SELECT COUNT(postid) AS newposts FROM post WHERE dateline > $unix_timestamp');
$totalnewthreads = number_format($countnewthreads['newposts']);
i know that the ending of the query would be the only difference. my problem is being able to give the unix timestamp for today. like september 9 2004 0:0:0am ... just not sure how to go about that.
Slapyo
09-09-2004, 11:11 PM
i think i might have it. lemme know if this is correct:
$todaysdate = date("d F Y");
$timetoday = strtotime($todaysdate);
$countdailythreads = $DB_site->query_first("SELECT COUNT(postid) AS dailyposts FROM post WHERE dateline > $timetoday");
$totaldailythreads = number_format($countdailythreads['dailyposts']);
Xenon
09-11-2004, 04:11 PM
you can use the mktime() function ;)
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.