php - 24 hours of values -


i have sql table : date (y-m-d) / time (00:00:00) / power (int)

when select date inline datepicker, trying post 3 highcharts graph (one-24 hours, two-31 days of month, three-12 months of year) , need values out of table chart created.

for day, need 24 values each hour '100,200,300,200,300 etc..'

here php "day" not working...

<?php $choice = (isset($_post['choice']))            ? date("y-m-d",strtotime($_post['choice']))            : date("y-m-d");  $con = mysql_connect("localhost","root","xxxxxx");   if (!$con)  {     die('could not connect: ' . mysql_error());   }   mysql_select_db("inverters", $con);   $sql = "select hour(time), count(power)  feed  time = date_sub('".$choice."', interval 24 hour)  group hour(time)  order hour(time)";  $res = mysql_query($sql) or die('sql='.$sql."\n".mysql_error());  $row = mysql_fetch_assoc($res);  echo $row['choice'].'<br />';  ?> 

this has been confirmed individual code not work, have helpful solution fix error ?

alan

at moment, select gives results happened exactly 24 hours before current moment. need range. example 1 hour (indentation added clarity):

where `time` between     date_sub('".$choice."', interval 24 hour)     , date_sub('".$choice."', interval 23 hour)  

this way, you'll results time in 1-hour range of "now - 24 hours" , "now - 23 hours". between operator equivalent this:

where `time` >= date_sub('".$choice."', interval 24 hour)    , `time` <= date_sub('".$choice."', interval 23 hour)  

Comments

Popular posts from this blog

Add email recipient to all new Trac tickets -

400 Bad Request on Apache/PHP AddHandler wrapper -

php - Change action and image src url's with jQuery -