24 hours of values

后端 未结 3 1749
离开以前
离开以前 2021-01-25 17:38

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, t

3条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-25 18:00

    You need a loop to walk over the rows:

    $sql = "
    SELECT HOUR(time) as h, power
    FROM feed 
    WHERE date = '".$choice."' 
    ORDER BY HOUR(time)"; 
    
    $res = mysql_query($sql) or die('sql='.$sql."\n".mysql_error()); 
    
    while($row = mysql_fetch_assoc($res)) {
        echo $row['h'].":".$row['power']'
    '; }

    This will give you the power per day for a given month:

    $sql = "
    SELECT DAY(date) as d, SUM(power) as powerday
    FROM feed 
    WHERE MONTH(date) = '".$month."' 
    GROUP BY DAY(date) 
    ORDER BY DAY(date)"; 
    
    $res = mysql_query($sql) or die('sql='.$sql."\n".mysql_error()); 
    
    while($row = mysql_fetch_assoc($res)) {
        echo $row['d'].":".$row['powerday']'
    '; }

提交回复
热议问题