这是我正在处理的代码。我正在为我的移动设备创建API。
<?php
$property_id=$_GET['property_id'];
$res_image=mysql_query("select *
from fak_property_image
where property_id='".$property_id."'");
$i=0;
while($row2=mysql_fetch_array($res_image)){
// $status[$i]['property_id']=$row2['property_id'];
// $status[$i]['image']=$row2['image'];
$status[$i]['path']=$row2['path'];
$i++;
}
echo json_encode( $status );exit;
?>
输出正在跟随
[
{"path":"http:\/\/grandthecompany.com\/admin\/uploads\/IMG_0008.1525441844.JPG"},
{"path":"http:\/\/grandthecompany.com\/admin\/uploads\/IMG_0009.1525441844.JPG"},
{"path":"http:\/\/grandthecompany.com\/admin\/uploads\/IMG_0013.1525441844.JPG"},
{"path":"http:\/\/grandthecompany.com\/admin\/uploads\/IMG_0015.1525441844.JPG"},
{"path":"http:\/\/grandthecompany.com\/admin\/uploads\/IMG_0016.1525441844.JPG"},
{"path":"http:\/\/grandthecompany.com\/admin\/uploads\/IMG_0074.1525441844.JPG"},
{"path":"http:\/\/grandthecompany.com\/admin\/uploads\/IMG_0210.1525441844.JPG"},
{"path":"http:\/\/grandthecompany.com\/admin\/uploads\/IMG_0211.1525441844.JPG"},
{"path":"http:\/\/grandthecompany.com\/admin\/uploads\/IMG_1400.1525441844.JPG"},
{"path":"http:\/\/grandthecompany.com\/admin\/uploads\/IMG_1903.1525441844.jpg"},
{"path":"http:\/\/grandthecompany.com\/admin\/uploads\/IMG_1904.1525441844.jpg"},
{"path":"http:\/\/grandthecompany.com\/admin\/uploads\/IMG_1905.1525441844.jpg"},
{"path":"http:\/\/grandthecompany.com\/admin\/uploads\/IMG_1906.1525441844.jpg"}
]
但我的要求是像这样显示输出
[
{
"path":
"http:\/\/grandthecompany.com\/admin\/uploads\/IMG_0008.1525441844.JPG",
"http:\/\/grandthecompany.com\/admin\/uploads\/IMG_0009.1525441844.JPG",
"http:\/\/grandthecompany.com\/admin\/uploads\/IMG_0013.1525441844.JPG",
"http:\/\/grandthecompany.com\/admin\/uploads\/IMG_0015.1525441844.JPG",
"http:\/\/grandthecompany.com\/admin\/uploads\/IMG_0016.1525441844.JPG",
"http:\/\/grandthecompany.com\/admin\/uploads\/IMG_0074.1525441844.JPG",
"http:\/\/grandthecompany.com\/admin\/uploads\/IMG_0210.1525441844.JPG",
"http:\/\/grandthecompany.com\/admin\/uploads\/IMG_0211.1525441844.JPG",
"http:\/\/grandthecompany.com\/admin\/uploads\/IMG_1400.1525441844.JPG",
"http:\/\/grandthecompany.com\/admin\/uploads\/IMG_1903.1525441844.jpg",
"http:\/\/grandthecompany.com\/admin\/uploads\/IMG_1904.1525441844.jpg",:
"http:\/\/grandthecompany.com\/admin\/uploads\/IMG_1905.1525441844.jpg",
"http:\/\/grandthecompany.com\/admin\/uploads\/IMG_1906.1525441844.jpg"
}
]
我试图使用mysql_fetch_all获取所有数据,但它无法正常工作。请帮忙。
由于
答案 0 :(得分:0)
尝试以下方法:
$status['path'][] = $row2['path'];
而不是:
$status[$i]['path']=$row2['path'];
但你肯定应该使用PDO,除了这个代码容易受到SQL注入。