Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 通过codeigniter中的查询详细统计行数_Php_Mysql_Codeigniter - Fatal编程技术网

Php 通过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

我正在用codeigniter制作一个旅行社网站。我从数据库中获取非洲的目的地并显示在页面上。 这是我的控制器代码:

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();

}

你是否尝试使用
分组依据
目的地?你是否尝试使用
分组依据
目的地?我将如何在查看页面中获取总数?我将如何在查看页面中获取总数?我还需要数据,它将只返回行数。我还需要数据,它将只返回行数