在codeigniter中获取表格的总列字段?

时间:2016-01-09 07:21:37

标签: php mysql codeigniter

如何从控制器函数中的结果数组中获取总列字段?

  

我在$fields = $query->list_fields()上使用类似model的方法,但我怎样才能从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; 
    }
} 

1 个答案:

答案 0 :(得分:1)

试试这个,

控制器:

true

型号:

Monday

在这里,您只需要从$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中运行。< / p>