Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/271.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_Codeigniter_Activerecord - Fatal编程技术网

Php 我想使用codeigniter中的活动记录按函数排序

Php 我想使用codeigniter中的活动记录按函数排序,php,codeigniter,activerecord,Php,Codeigniter,Activerecord,我的注册表中有三种状态类型。它们正在等待、跟进和完成。因此,我想使用活动记录获取每个状态的计数。这是我写的代码。但是我没有得到任何传递给控制器的值。 这是模型代码 <?php class Manager_Profile_Model extends CI_Model{ function index(){ $this->db->select('Status,COUNT(Status) AS count'); $this->db->

我的注册表中有三种状态类型。它们正在等待、跟进和完成。因此,我想使用活动记录获取每个状态的计数。这是我写的代码。但是我没有得到任何传递给控制器的值。 这是模型代码

<?php
class Manager_Profile_Model extends CI_Model{

    function index(){
        $this->db->select('Status,COUNT(Status) AS count');
        $this->db->order_by('Status');
        $query = $this->db->get('register');
        foreach($query -> result() as $row){
            $data[] = array(
                 'status' =>$row->Status,
                'count' => $row->count

                );
            }
        return $data;
        }
    }

?>

这是控制器

<?php
class Manager_Profile_Controller extends CI_Controller{
    function index(){
        $this->load->model('Manager_Profile_Model');
        $data = $this->Manager_Profile_Model;

        print_r($data);

   }
}


如果有人能帮助我,那真是太好了。感谢您的帮助

使用
分组方式
,如下所示:

function index(){
    $this->db->select('Status,COUNT(Status) AS count');
    $this->db->group_by('Status');
    $query = $this->db->get('register');
    foreach($query -> result() as $row){
        $data[] = array(
             'status' =>$row->Status,
            'count' => $row->count

            );
        }
    return $data;
    }
}


感谢您的回复,但在这里,我没有将数据库中的所有状态类型发送给控制器。我是否需要对模型代码进行任何更改,以获取所有状态类型及其计数???
class Manager_Profile_Controller extends CI_Controller{
    function index(){
        $this->load->model('Manager_Profile_Model');
        $data = $this->Manager_Profile_Model->index();

        print_r($data);

   }
}