24小时值 [英] 24 hours of values

查看:91
本文介绍了24小时值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个sql表:date(Ymd)/ time(00:00:00)/ power(INT)



当我从内联中选择一个日期datepicker,我试图发布3 HighCharts图表(一个24小时,一个月的三到三十一天,一年三到十二个月),我需要从表中获取要创建的图表的值。 p>

对于当天,我需要每个小时的数据值为100,200,300,200,300等。



这里是PHP对于天,但它不工作...

 <?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(inverterters,$ con);
$ sql =SELECT HOUR(time),COUNT(power)
FROM feed
WHERE time = DATE_SUB('。$ choice。',INTERVAL 24 HOUR)
GROUP BY HOUR(时间)
ORDER BY HOUR(时间);
$ res = mysql_query($ sql)or die('sql ='。$ sql。\\\
.mysql_error());
$ row = mysql_fetch_assoc($ res);
echo $ row ['choice']。'< br />';
?>

其他人已经确认代码不起作用,任何人都有一个有用的解决方案修复错误?



Alan

解决方案

你的帮助!



问题出在第一个字符串,我只需要更改日期格式,除了你精彩的例子!

  $ choice =(isset($ _ POST ['choice']))? date(m,strtotime($ _ POST ['choice'])):date(m); 

非常感谢!



Alan


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 !

$choice = (isset($_POST['choice'])) ? date("m",strtotime($_POST['choice'])) : date("m"); 

Thank You Very Much !

Alan

这篇关于24小时值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆