$sql = "SELECT * FROM `demo_viewer` WHERE 1 ";
$viewer = mysqli_query($mysqli,$sql);
$view = array();
while ($row = mysqli_fetch_array($viewer)){
$view[] = $row;
}
$viewer = json_encode($view,JSON_NUMERIC_CHECK);
为什么这是代码没有显示数据... 数据库连接没问题,但如果下面的代码显示这个数据..
$sql = "SELECT SUM(numberofview) as count FROM demo_viewer
GROUP BY YEAR(created_at) ORDER BY created_at";
$viewer = mysqli_query($mysqli,$sql);
$viewer = mysqli_fetch_all($viewer,MYSQLI_ASSOC);
$viewer = json_encode(array_column($viewer, 'count'),JSON_NUMERIC_CHECK);
答案 0 :(得分:0)
试试这个,
mysqli_query($mysqli,'SET NAMES utf8mb4');
$sql = "SELECT * FROM `demo_viewer` WHERE 1 ";
$viewer = mysqli_query($mysqli,$sql);
$view = array();
while ($row = mysqli_fetch_array($viewer,MYSQLI_ASSOC)){
$view[] = $row;
}
$viewer = json_encode($view, JSON_PARTIAL_OUTPUT_ON_ERROR | JSON_FORCE_OBJECT | JSON_NUMERIC_CHECK);
修改强>
mysqli_query($mysqli,'SET NAMES utf8mb4');
$sql = "SELECT numberofclick FROM `demo_viewer` GROUP BY YEAR(created_at) ORDER BY created_at ";
$viewer = mysqli_query($mysqli,$sql);
$view = array();
while ($row = mysqli_fetch_array($viewer,MYSQLI_ASSOC)){
$view[] = $row['numberofclick'];
}
$viewer = json_encode($view, JSON_PARTIAL_OUTPUT_ON_ERROR | JSON_FORCE_OBJECT | JSON_NUMERIC_CHECK);
PS:你不应该使用select * from table。因为Highchart需要一个列值。不是所有的栏目。