Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/239.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在单个项中添加数组项?_Php_Android_Arrays_Api_Sorting - Fatal编程技术网

Php 如何在单个项中添加数组项?

Php 如何在单个项中添加数组项?,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

这是我正在编写的代码。我正在为我的移动设备创建一个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",
        "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'];