<?php
header("Content-Type:application/json;charset=UTF-8");
$uphonenumber = $_POST['phonenumber'];//post获得手机号码表单值
$json = '';
$data = array();
include('init.php');//链接数据库
//$sql = "SELECT * FROM yffice_project where uphonenumber = $uphonenumber";
$sql = "SELECT * FROM yffice_project where uphonenumber = $uphonenumber";
mysql_query("set names utf8");
$result = mysql_query($sql);//执行sql
if($result){
//echo "查询成功";
while ($row = mysql_fetch_array($result))
{
$data["uid"]=$row["uid"];
$data["pcontent"]=$row["pcontent"];
$data["src"]=explode(",",$row["ppic"]);
$data["pdate"]=$row["pdate"];
$data["pweek"]=$row["pweek"];
$data["pweather"]=$row["pweather"];
}
$json=json_encode($data);
echo $json;
}else{
echo "查询失败";
}
mysql_close();//关闭数据库
?>
2 回答
GCT1015
TA贡献1827条经验 获得超4个赞
你的while
循环里的赋值有问题,一直在重复为同一个键名赋值。
正确的应该是:
$data[] = [
'uid' => $row["uid"],
'pcontent' => $row["pcontent"],
'src' => explode(",",$row["ppic"]),
'pdate' => $row["pdate"],
'pweek' => $row["pweek"],
'pweather' => $row["pweather"]
];
这种形式;
- 2 回答
- 0 关注
- 489 浏览
添加回答
举报
0/150
提交
取消