Jump to content


Photo

Counter per Hour...


  • Please log in to reply
1 reply to this topic

#1 SharkBait

SharkBait
  • Members
  • PipPipPip
  • Advanced Member
  • 845 posts
  • LocationMetro Vancouver, BC

Posted 15 June 2006 - 08:50 PM

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:

SELECT count(*) FROM myTable WHERE date_entered >= AN AN HOUR AGO FROM NOW

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

Thanks

#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,017 posts

Posted 15 June 2006 - 09:37 PM

You could do the whole day with

$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>";
}

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users