[英]count number of rows with detail through query in codeigniter
I am making a travel agency website in codeigniter. 我正在codeigniter建立一个旅行社网站。 I am getting destination of africa from my database and displaying on a page.
我从我的数据库中获取非洲的目的地并在页面上显示。 here is my code of controller:
这是我的控制器代码:
public function africa() {
$data['africa']= $this->Travel->africa_des();
$this->load->view('africa', $data);
}
my Model: 我的型号:
function africa_des() {
$this->db->distinct();
$this->db->select();
$this->db->from('travels_detail');
$this->db->like('region', 'africa');
$this->db->limit(5);
$query= $this->db->get();
return $query->result_array();
}
I want to get total number of flights of each destination that i have in my database. 我想获得我在数据库中拥有的每个目的地的总航班数。 For instance I have 25 flights of Abuja so I want to get that number with Abuja destination.
例如,我有25个阿布贾航班,所以我想从阿布贾目的地获得这个号码。
Anyone have any idea? 任何人都有任何想法?
Try this one 试试这个吧
public function africa_desc(){
$this->db->distinct();
$this->db->select('*');
$this->db->from('travels_detail');
$this->db->where('region', 'africa');
$this->db->limit(5);
$query= $this->db->get();
return $query->result_array();
}
When you are using $this->db->distinct()
you must use $this->db->group_by('column_name')
see this answer https://stackoverflow.com/a/19509869/6098616 . 当你使用
$this->db->distinct()
,必须使用$this->db->group_by('column_name')
请参阅此答案https://stackoverflow.com/a/19509869/6098616 。 In your case I will assume that destination
is your column name. 在您的情况下,我将假设
destination
是您的列名称。
public function africa_desc(){ $this->db->select('*'); $this->db->distinct(); $this->db->group_by('destination'); $this->db->from('travels_detail'); $this->db->where('region', 'africa'); $this->db->limit(5); $query= $this->db->get(); return $query->result_array(); }
Hope this will help. 希望这会有所帮助。
Try this to count flights 试试这个计算航班
public function africa_desc(){
$this->db->select('*');
$this->db->distinct();
$this->db->group_by('destination');
$this->db->from('travels_detail');
$this->db->where('region', 'africa');
$this->db->limit(5);
$query= $this->db->get();
return $query->num_rows();
} }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.