PHP: can't encode json with multiple rows

前端 未结 5 805
旧时难觅i
旧时难觅i 2020-12-10 17:49

I\'ve spent a couple of hours looking through several the similar answers before posting my problem.

I\'m retrieving data from a table in my database, and I want to

5条回答
  •  星月不相逢
    2020-12-10 18:03

    I must have spent 15 hours on this issue. Every variation discussed above was tried. Finally I was able to get the 'standard solution' working. The issue, very oddly, appears to be this:

    When the interval is set beyond 14 hours, json appears to be unable to parse it. There must be a limit to JSON.

    $sql= "SELECT cpu_name, used, timestamp FROM tbl_cpu_use WHERE timestamp>(NOW() - INTERVAL 14 HOUR) ORDER BY id";
    $result=mysql_query($sql);
    if ($result){
        $i=0;
        $return =[];
        while($row = mysql_fetch_array($result, MYSQL_NUM)){
            $rows[] = $row;
        }
        echo json_encode($rows);
    }else{
        echo "ERROR";
    }
    

提交回复
热议问题