I have a sql table : date (Y-m-d) / time (00:00:00) / power (INT)
When I select a date from an inline datepicker, I am trying to post 3 HighCharts graph (one-24 hours, two-31 days of month, three-12 months of year) and I need to get the values out of the table for the chart to be created.
For the day, I need the 24 values for each hour ‘100,200,300,200,300 etc..’
Here is the PHP for the “day” but it is 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)
FROM feed
WHERE time = DATE_SUB('".$choice."', INTERVAL 24 HOUR)
GROUP BY HOUR(time)
ORDER BY 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 by another individual that the code does not work, would anyone have a helpful solution to fix the error ?
Alan
Thank you everyone for all your help !
The problem was in the first string, I only had to change the date format in addition to your wonderful examles !
Thank You Very Much !
Alan