php - how to retrieve count from mysql between 2 hours -


consider following table:

create table `trans` (   `transid` varchar(255) not null,   `affid` varchar(255) not null,   `timestamp` varchar(255) not null,   unique key `transid` (`transid`) ) engine=myisam default charset=utf8; 

and php code:

case "today":     $sale=[];     ($i = 0 ; $i < 23 ; $i++) {         $hours[]= $i;         $clicks[$i]=$api["clicks"][$i];     }         break; 

i want add $sale array today's count of sales each hour. like: $hours[5] = select count(*) trans .. date between today's 04:59:59 - 06:00:00.

first of all, if trying use unix timestamps timestamp field, stop now. making life painful. use mysql timestamp field. there few use cases idea use unix timestamp field.

if had timestamp field like

select hour(`timestamp`) `hour`, sum(`transid`) `transaction_count` trans `timestamp` concat(date(now()),'%') group `hour` order `hour` asc 

that give sales count every hour of current day. make sure add index on timestamp optimal query performance.

if don't have timestamp, need utilize from_unixtime() conversions, prevent being able use index on timestamp


Comments

Popular posts from this blog

ios - iPhone/iPad different view orientations in different views , and apple approval process -

php - HTTP_REFERER woes: How can I allow access to a specific page, only when a visitor has visited another specific page beforehand? -

java Extracting Zip file -