开发者

Daterange sorted by date and group by hour

开发者 https://www.devze.com 2023-01-25 18:49 出处:网络
I have a msql table that has data input ever hour of every day, so each date is entered 24 times and then a hour field as seen below...

I have a msql table that has data input ever hour of every day, so each date is entered 24 times and then a hour field as seen below...

How do I get the information between a daterange ?

Here is what I have, but I think the time is stopping it from working...

$sql = "SELECT * FROM report WHERE date BETWEEN '$start' AND '$end'";

Hee is the table I want to get information by the date...

unit ID | Date | Time | Power | Volts | Current |

1         10/15/2010    21:00:00         0            220          100
1         10/开发者_JS百科15/2010    22:00:00         0            220          100
1         10/15/2010    23:00:00         0            220          100
1         10/16/2010    00:00:00         0            220          100
1         10/16/2010    01:00:00         0            220          100
1         10/16/2010    02:00:00         0            220          100
1         10/16/2010    03:00:00         0            220          100
1         10/16/2010    04:00:00         0            220          100
1         10/16/2010    05:00:00       245            220          100
1         10/16/2010    06:00:00       360            220          100
1         10/16/2010    07:00:00       596            220          100
1         10/16/2010    08:00:00      1567            220          100
1         10/16/2010    09:00:00      1568            220          100
1         10/16/2010    10:00:00      1598            220          100
1         10/16/2010    11:00:00      1642            220          100
1         10/16/2010    12:00:00      1658            220          100
1         10/16/2010    13:00:00      1664            220          100
1         10/16/2010    14:00:00      1598            220          100
1         10/16/2010    15:00:00      1527            220          100
1         10/16/2010    16:00:00       980            220          100
1         10/16/2010    17:00:00       410            220          100
1         10/16/2010    18:00:00       208            220          100
1         10/16/2010    19:00:00         0            220          100
1         10/16/2010    20:00:00         0            220          100
1         10/16/2010    21:00:00         0            220          100
1         10/16/2010    22:00:00         0            220          100
1         10/16/2010    23:00:00         0            220          100
1         10/17/2010    00:00:00         0            220          100
1         10/17/2010    01:00:00         0            220          100
1         10/17/2010    02:00:00         0            220          100

The Date is DATE, the Time field is TIME, Power, Volt and Current are FLOAT.

The $start and $end are dates from a datepicker

    $start = (isset($_POST['start1'])) ? date("Y-m-d",strtotime($_POST['start1'])) : date("Y-m-d");

$end   = (isset($_POST['end1'])) ? date("Y-m-d",strtotime($_POST['end1'])) : date("Y-m-d");


No, if you want all the points from all the dates, you can ignore you time column and your query will work just fine.


You need to remove the single (') quotes from the variables $start and $end.

By using single quotes, you are making your variables a string.

Just use

$sql = "SELECT * FROM report WHERE date BETWEEN $start AND $end";

In your mysql table the date is in the format m-D-Y, whereas in your php code, its Y-m-d. The date format in ur php code should be similar to your mysql date format.

0

精彩评论

暂无评论...
验证码 换一张
取 消