PDA

View Full Version : Probably very easy: total # of posts today


futureal
08-28-2001, 07:30 AM
Hi,

I am hoping I could add a little tidbit of info on my Forum Home display that, similar to "Total Posts: xx" and "Total Threads: xx" says something to the effect of "Total Posts Today: xx"

In an ideal world, it would only count posts on that particular day, thus resetting to zero at the midnight hour. It seems like something that should be pretty easy...

(but also makes me wonder, from an efficiency standpoint, if it's a good idea to be counting and re-counting all of the posts that day each time somebody loads the page...)

Also, I did do a search for this and only came up with a thread from almost a year ago where somebody asked a similar question but got no response.

So if anybody has a simple solution, thanks in advance! As you can see I am a PHP/MySQL newbie... learning a bit here and there... thanks!

Admin
08-29-2001, 05:24 PM
Add this code:
// get number of posts today
$datecut=time()-(86400);
$getpoststoday=$DB_site->query_first("SELECT count(*) AS count FROM post WHERE dateline>='$datecut'");
$poststoday=$getpoststoday[count];
in index.php, right before
// get newest member
Now you can use $poststoday anywhere in your forumhome template to show the number of posts today.

futureal
08-29-2001, 11:21 PM
Thanks FireFly, works great!

futureal
08-30-2001, 12:04 AM
I actually changed it a little bit. After some poking around on php.net I came up with this line:

$datecut = mktime(0,0,0,date("m"), date("d"), date("y"));

That will reset it at midnight of each day, according to the system time. The other version works for the past 24 hours.

Now that I've actually modified a line of PHP code all by myself, I feel quite special :) Thanks again!

Admin
08-30-2001, 04:47 AM
No problem mate. :)

FWC
08-30-2001, 06:01 AM
Now you can use $poststoday anywhere in your forumhome template to show the number of posts today.

Another cool one, FireFly. I am going to be in trouble when the next upgrade comes out. I can't stop myself! :D

Admin
08-30-2001, 06:14 AM
Yeah I know what you mean.
Unless the next version is a major one (2.1.0), I don't think I'm gonna upgrade.
I have so many hacks installed, it's really tough! :(

But I'm glad you like this. :)