首页 > 解决方案 > RestApi php中的过滤器数组

问题描述

我正在使用 RestApI IN Codeigniter 我有两个下表

表 - 城市

id  city
1   abc
2   xyz
3   abp
4   djh

表 - 位置

id  address cityId
1   lorem1  2
2   lorem2  3
3   lorem3  2
4   lorem4  1

这是我的查询,它工作正常,但以以下格式显示

{
    "name": "xyz",
            "address": "lorem1",
}
{
    "name": "xyz",
            "address": "lorem3",
}

But i want to result like city list and related address in json
Expected output

cityname : xyz
{
    ///details of xyz
    address : lorem1
    address : lorem3
}
cityName :abc
{
    address : lorem1
}   
...

这是我的查询

$this->db->select('c.*,l.address ');
$this->db->from('city c');
$this->db->join('locality l', 'c.id=l.cityID');
$this->db->order_by("c.name", "asc");

$query = $this->db->get();

if ($query->num_rows() > 0) 
{
    $rows = $query->result_array();  
} 

标签: phpmysqlarrayscodeigniter

解决方案


推荐阅读