0

我试图从数据库中获取每天的最低和最高温度。但他以错误的顺序检索日期年份我得到这样的值:

数组( [00-00-0000] => 22 [00-08-2013] => 22 [01-08-0201] => 24 [01-08-0213] => 24 [01-08-2013] 。 ..

如果我使用 PHPmyAdmin 验证表中的数据,一切似乎都可以。

代码:

$query = "SELECT  DATE_FORMAT(`Datum`, '%d-%m-%Y') as Datum1, min(`Temperatuur`)as minTemp ,max(`Temperatuur`)as maxTemp FROM `tableGreenhouse`  GROUP BY `Datum1` ORDER BY 1";

$result = $mysqli->query($query) or die($mysqli->error.__LINE__);

if($result->num_rows > 0) {
    while($row = $result->fetch_assoc()) {
        $date = $row['Datum1'];
        $Temp1 = $row['minTemp'];
        $Temp2 = $row['maxTemp'];

        $dataArray1[$date]=$Temp1;
        $dataArray2[$date]=$Temp2;  

    }

}

print_r($dataArray1);
print_r($dataArray2);
4

1 回答 1

0

您的查询似乎没有任何问题。

也许您可以尝试使用以下代码将变量转换为某种类型:

if ($result->num_rows > 0) {
    // In some cases, code breaks if you do not do this...
    // Experienced it myself a few times.
    $dataArray1 = array();
    $dataArray2 = array();

    while($row = $result->fetch_assoc()) {

        /* For error checking, enable following statement: */
        // var_dump($row);

        $date = (string)$row['Datum1'];
        $Temp1 = (float)$row['minTemp'];
        $Temp2 = (float)$row['maxTemp'];

        $dataArray1[$date]=$Temp1;
        $dataArray2[$date]=$Temp2;
    }
}
于 2013-08-25T16:22:39.713 回答