需要把數(shù)據(jù)庫數(shù)據(jù)與echart連接起來,但是echart需要json格式,所以想用php把數(shù)據(jù)庫中數(shù)據(jù)轉(zhuǎn)化為json格式,然后再在echart里調(diào)用?,F(xiàn)在做到了這一步,希望大家?guī)兔纯?,越詳?xì)越好,如果有其他方法也可以,因?yàn)樾枰D(zhuǎn)換的數(shù)據(jù)量很大<?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)?{
????//?輸出每行數(shù)據(jù)
????while($row?=?mysql_fetch_assoc($result))?{
????????echo?"<br>?WIFIAPTag:?".?$row["WIFIAPTag"].?"?passengerCount:?".?$row["passengerCount"].?"?timeStamp:"?.?$row["timeStamp"];
????}
}?else?{
????echo?"0?個(gè)結(jié)果";
}
??mysqli_close($con);
?>
php把數(shù)據(jù)庫數(shù)據(jù)轉(zhuǎn)化為json格式
無無法師
2016-10-19 13:36:16