1

I want this human readable words into php code:

Take all values from column "Ratings" WHERE Time >= 24 hours Split them into 1 hour each Take average Rating values for each hour and put them into 24 variables

WhatI'm doing now is a bad long code :/

I'm taking them an hour after another, each one in a separate function where I specify an hour via mysql select statement!

I'm new in programming, and I couldn't figure out what to do to get all values at once, and split them into 1 hour each

Thanks

4

2 回答 2

1

编辑:更改了小提琴,因此它使用时间作为整数,表示自 1970 年 1 月 1 日以来的秒数。

看看这个小提琴:http ://sqlfiddle.com/#!2/6e6b6/5/0 它每小时返回评级平均值。这是你需要的吗?我认为您可以根据其他需求调整查询。

您可以在http://dev.mysql.com/doc/refman/5.6/en/date-and-time-functions.html阅读更多相关信息

于 2013-07-01T03:18:11.423 回答
0

知道了,经过这么多搜索。学习是美好的:)

这是代码

$mysql = "select date_format(from_unixtime(Time), '%H') as hour, avg(Rate) from za7ma1 group by hour";

$result = mysql_query($mysql) or die(mysql_error());

            // Print out result
    while($row = mysql_fetch_array($result)){
        echo "The average for this hour ". $row['hour']. " is ".$row['avg(Rate)'];
        echo "<br />";
    }

感谢 Alexander Jardim 提供的出色工具http://sqlfiddle.com/#!2/6e6b6/5/0,它让我看到了 avg() mysql 函数

于 2013-07-03T23:04:42.207 回答