Php 通过codeigniter中的查询详细统计行数
我正在用codeigniter制作一个旅行社网站。我从数据库中获取非洲的目的地并显示在页面上。 这是我的控制器代码:Php 通过codeigniter中的查询详细统计行数,php,mysql,codeigniter,Php,Mysql,Codeigniter,我正在用codeigniter制作一个旅行社网站。我从数据库中获取非洲的目的地并显示在页面上。 这是我的控制器代码: public function africa() { $data['africa']= $this->Travel->africa_des(); $this->load->view('africa', $data); } 我的模型: function africa_des() { $this->db->distinc
public function africa() {
$data['africa']= $this->Travel->africa_des();
$this->load->view('africa', $data);
}
我的模型:
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();
}
我想获得数据库中每个目的地的航班总数。例如,我有25个阿布贾航班,所以我想得到阿布贾目的地的号码
有人知道吗?试试这个
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();
}
试试这个
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();
}
当您使用
$this->db->distinct()
时,必须使用$this->db->group\u by('column\u name')
查看此答案。在您的情况下,我将假定目的地
是您的列名
public function\u 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();
返回$query->result_array();
}
当您使用$this->db->distinct()
时,必须使用$this->db->groupby('column\u name')
查看此答案。在您的情况下,我将假定目的地
是您的列名
public function\u 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();
返回$query->result_array();
}
试试这个来计算航班数
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();
}试试这个来计算航班数
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();
}你是否尝试使用
分组依据
目的地?你是否尝试使用分组依据
目的地?我将如何在查看页面中获取总数?我将如何在查看页面中获取总数?我还需要数据,它将只返回行数。我还需要数据,它将只返回行数