我有一个包含地方详细信息的表名app_places see image of my table
问题:我想只获取一次数据并想以json格式显示相同的place_id
这是我的代码:
load
我需要以下输出
$sql="SELECT place_id FROM `app_places` ";
$check= mysqli_query($conn, $sql);
while ($row = mysqli_fetch_array($check,MYSQLI_ASSOC)) {
$place_id=$row['place_id'];
$sql1="SELECT * FROM app_places where place_id='".$place_id."' limit 1";
//var_dump($sql1);
$check2= mysqli_query($conn, $sql1);
while($result=mysqli_fetch_array($check2,MYSQLI_ASSOC))
{
$json []= $result;
}
$json1 []= array("place"=>$json);
}
echo json_encode($json1);
但输出来自于此并非按照我的要求提前谢谢,请帮助我。
答案 0 :(得分:0)
$json = array();
$sql = "SELECT description, place_id, image FROM app_places GROUP BY place_id";
$check = mysqli_query($conn, $sql);
while ($result = mysqli_fetch_assoc($check))
{
$json[] = $result;
}
echo json_encode($json);