如何从controller函数的结果数组中获取total column字段?.
我是通过在$fields = $query->list_fields()上使用likemodel来实现这一点的,但我如何才能从controller中获得它。
控制器功能:

$result = $this->admin_model->national_certificate_user_search_print($start_date, $end_date);
$total = sizeof($result);  // getting total rows

模型函数:
public function national_certificate_user_search_print($start_date, $end_date) {
        $tablename = 'national_certificate';
        $query = $this->db->select('user_name,gurdiant_name,mother_name,prm_village_name,prm_post_office,prm_thana,prm_district,prsnt_address,prsnt_ward,prsnt_post_office,prsnt_thana,prsnt_district')
                         ->from($tablename)
                         ->where( "uploaded_date BETWEEN '$start_date' AND '$end_date' ", NULL, FALSE )
                         ->get();
       $result = $query->result_array();
    //   var_dump($query->num_fields());
       return $result;
    }
}

最佳答案

试试这个,
控制器:

$result = $this->admin_model->national_certificate_user_search_print($start_date, $end_date);
$total = $result->list_fields();  //this will work now with Object

型号:
public function national_certificate_user_search_print($start_date, $end_date) {
        $tablename = 'national_certificate';
        $query = $this->db->select('user_name,gurdiant_name,mother_name,prm_village_name,prm_post_office,prm_thana,prm_district,prsnt_address,prsnt_ward,prsnt_post_office,prsnt_thana,prsnt_district')
                         ->from($tablename)
                         ->where( "uploaded_date BETWEEN '$start_date' AND '$end_date' ", NULL, FALSE )
                         ->get();
       return $query;
    }
}

这里只需要从$query返回Model对象,然后可以在Controller中使用它,这样list_fields()函数就可以在controller中工作。

关于php - 获取在Codeigniter中的表的总列字段?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/34690845/

10-11 04:46