gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 23:39:56 25 4
gpt4 key购买 nike

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

I get that by using like $fields = $query->list_fields() on model but how can i get it from controller.

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;
}
}

最佳答案

试试这个,

Controller :

$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;
}
}

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

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com