需要把数据库数据与echart连接起来,但是echart需要json格式,所以想用php把数据库中数据转化为json格式,然后再在echart里调用。现在做到了这一步,希望大家帮忙看看,越详细越好,如果有其他方法也可以,因为需要转换的数据量很大<?php
header("Content-type: text/html; charset=utf-8");
$host='127.0.0.1';
$user='root';
$password='';
$database='mydatabase';
$con=mysqli_connect($host,$user,$password,$database);
//mysqli_query($con,"set names utf8");
$ss = "SELECT * FROM passenger";
$result = mysqli_query($con,$ss);
if (mysql_num_rows($result) > 0) {
// 输出每行数据
while($row = mysql_fetch_assoc($result)) {
echo "
WIFIAPTag: ". $row["WIFIAPTag"]. " passengerCount: ". $row["passengerCount"]. " timeStamp:" . $row["timeStamp"];
}
} else {
echo "0 个结果";
}
mysqli_close($con);
?>