2016-06-29 199 views
0

我想使用group by,以便我可以获取数据为country-state-district。我只想显示国家,然后州和地区级要添加复选框。查询 - 不正确答案

$this->db->distinct(); 
$this->db->select('country_name,s_name,dist_name'); 
$this->db->from('resource_details');  
$this->db->join('location','reso_dtail_location=loc_id');   
$this->db->join('go_state', 'go_stste_id = loc_state', 'left'); 
$this->db->join('go_country', 'num = loc_country', 'left'); 
$this->db->join('go_dist', 'id = loc_district', 'left'); 
$this->db->where('loc_id !=1 AND loc_id !=2'); 

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

    //result 
$location = $query->result(); 

但查询不使用group_by它仅显示第1记录

+0

你想要做什么?不明白 – Vinie

+0

我没有看到代码中的任何地方'group_by'? –

+0

请用'echo $ this-> db-> last_query()'检查你的查询,你得到的错误/结果是什么以及你想要的结果是什么? –

回答

0

您可以通过使用国家组后,给予正确的答案。这样你就可以得到明显的国家名称。但州和城市,你可以使用组concat。