Php 如何在单个项中添加数组项?
这是我正在编写的代码。我正在为我的移动设备创建一个APIPhp 如何在单个项中添加数组项?,php,android,arrays,api,sorting,Php,Android,Arrays,Api,Sorting,这是我正在编写的代码。我正在为我的移动设备创建一个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_fetc
<?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",
"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获取所有数据,但它不起作用。请帮忙
谢谢请尝试以下操作:
$status['path'][] = $row2['path'];
而不是:
$status[$i]['path']=$row2['path'];
但是您肯定应该使用PDO,此外,此代码对于SQL注入很容易受到攻击。您所需的输出无效。您是否需要
{“path”:[“url1”、“url2”、“url3”]}
?请不要使用mysql.*
函数。这些函数已弃用,并在PHP7中删除。您应该使用或。$status['path'][=$row2['path']代码>
$status[$i]['path']=$row2['path'];