【发布时间】:2016-04-05 06:16:58
【问题描述】:
我正在尝试将数据导出到 CSV。我只想要 CodeIgniter 中的 CSV 中的一些字段,但它说“您必须提交一个有效的结果对象”。我的代码做错了吗?
这是我尝试过的代码:
$projectdetails = $this->db->query('select hs_hr_employee.emp_number,hs_hr_employee.emp_firstname,hs_hr_employee.emp_middle_name,hs_hr_employee.emp_lastname,ohrm_customer.customer_id,ohrm_customer.name as customername,ohrm_project.project_id,ohrm_project.customer_id,ohrm_project.name as projectname,
ohrm_project_admin.*, hs_hr_employee.*
from hs_hr_employee,ohrm_customer,ohrm_project,
ohrm_project_admin where
ohrm_project_admin.project_id=ohrm_project.project_id and
ohrm_project.customer_id=ohrm_customer.customer_id and ohrm_project_admin.project_id=ohrm_project.project_id and ohrm_project_admin.emp_number=hs_hr_employee.emp_number
');
$this->load->dbutil();
$this->load->helper('download');
$delimiter = ",";
$newline = "\r\n";
foreach($projectdetails->result() as $projectdetails12)
{
$projectname=$projectdetails12->projectname;
$customername=$projectdetails12->customername;
$projectadmin=$projectdetails12->emp_firstname.$projectdetails12->emp_middle_name.$projectdetails12->emp_lastname;
$downloadprojectdetails=array('projectname'=>$projectname,'customername'=>$customername,'projectadmin'=>$projectadmin);
$filename = 'projectdetails.csv';
$data = $this->dbutil->csv_from_result($downloadprojectdetails, $delimiter, $newline);
force_download($filename, $data);
}
output using print_r
Array ( [0] => stdClass Object ( [emp_number] => 3 [emp_firstname] => Suresh [emp_middle_name] => [emp_lastname] => Katiki [customer_id] => 1 [customername] => suresh [project_id] => 2 [projectname] => fff) [1] => stdClass Object ( [emp_number] => 2 [emp_firstname] => praveen [emp_middle_name] => [emp_lastname] => reddy [customer_id] => 2 [customername] => praveen [project_id] => 3 [projectname] => ota ) [2] => stdClass Object ( [emp_number] => 1 [emp_firstname] => chandra [emp_middle_name] => [emp_lastname] => kanth [customer_id] => 3 [customername] => chandra [project_id] => 1 [projectname] => orangehrm ) [3] => stdClass Object ( [emp_number] => 4 [emp_firstname] => aashish [emp_middle_name] => [emp_lastname] => madiri [customer_id] => 4 [customername] => aashish [project_id] => 4 [projectname] => test) )
【问题讨论】:
-
显示
$this->dbutil->csv_from_result()的代码
标签: php codeigniter csv