【发布时间】:2016-03-10 06:38:00
【问题描述】:
下面是我的代码:
$this->db->select("city_id,loc_id,loc_name");
$this->db->from("locations");
$this->db->group_by("city_id");
$this->db->order_by("city_id", "asc");
$query = $this->db->get();
return json_encode($query->result_array());
它给我的结果如下:
[{"city_id":"1","loc_id":"17","loc_name":"Al Barsha"} {"city_id":"2","loc_id":"12","loc_name":"testt"}]
但我想得到喜欢
{"1":{"17":"Al Barsg","35":"XYZ"},"2":{"123":"ABC","44":"OtherName"}}
我不明白怎么做?
【问题讨论】:
-
你应该为它创建字符串!
-
如果有城市ID,如何创建字符串。我需要用城市表创建连接查询吗?
-
如果你不想 city_id 从你的查询中删除它
标签: mysql json codeigniter