21,886
社区成员
发帖
与我相关
我的任务
分享
<?php
header("Content-Type: text/html; charset=UTF-8");
$con = mysql_connect("localhost","root","root");
if (!$con)//判断是否连接成功
{
die('Could not connect: ' . mysql_error());
}
mysql_set_charset('utf8',$con);//指定连接数据库的编码
mysql_select_db("emp");
$q=mysql_query("SELECT * FROM tianqi ");//取出tianqi中所有的数据
while($en=mysql_fetch_object($q))
echo json_encode($en,JSON_UNESCAPED_UNICODE);//打印结果
exit;
mysql_close();
$arr = array();
while($en=mysql_fetch_object($q))
$arr[] = $en;
echo json_encode($arr,JSON_UNESCAPED_UNICODE);//打印结果
exit;
while($en=mysql_fetch_object($q))
echo json_encode(array($en),JSON_UNESCAPED_UNICODE);//打印结果
exit;
我改了这个,结果是这样[{"id":"1","location":"汉字","oxygen":"3.33","negative":"23.2","humidity":"22","temp":"2.33","pm":"6"}][{"id":"4","location":"百度","oxygen":"13","negative":"151","humidity":"1","temp":"1","pm":"1151"}]