Jump to content

Archived

This topic is now archived and is closed to further replies.

SharkBait

Counter per Hour...

Recommended Posts

Not sure how I would set up for something like this.


I have a site where users enter information in and it gets time stamped to a MySQL Database.

What I want to do is display to the users how many entries are entered at any given time over the course of an hour.

So an Entries Per Hour kinda deal.

Would I make the query look like:

[code]
SELECT count(*) FROM myTable WHERE date_entered >= AN AN HOUR AGO FROM NOW
[/code]

Not sure if I would use SQL's time functions or PHP's Time functions, and how :)

Thanks

Share this post


Link to post
Share on other sites
You could do the whole day with

[code]$res = mysql_query("SELECT DATE_FORMAT(tstamp, '%h %p') as hour, COUNT(*) as total
                FROM tablename
                GROUP BY hour") or die(mysql_error());
while (list($hour, $total) = mysql_fetch_row($res))  {
    echo "$hour : $total<br>";
}[/code]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.