我試圖將數據導出爲CSV。我只想在CodeIgniter中有一些CSV字段,但它說「你必須提交一個有效的結果對象」。我在我的代碼中做錯了什麼?如何在CodeIgniter中僅添加來自查詢的一些列
這是我試過的代碼:
$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))
顯示的代碼'$這個 - > dbutil-> csv_from_result()' – Vinie