如何在codeigniter中向csv添加静态值

时间:2016-04-13 12:40:02

标签: php codeigniter

我正在尝试在codeigniter中向csv添加静态值我从数据库中获取查询但我需要在csv中添加静态值是否可以添加?

$searchtimesheet = $this->db->query('SELECT  ohrm_project.name AS ohrm_projectname, TIME_FORMAT(SEC_TO_TIME(ohrm_timesheet_item.duration),"%Hh %im") as duration  ,ohrm_timesheet_item.date AS date,concat(hs_hr_employee.emp_firstname," ",hs_hr_employee.emp_middle_name," ", hs_hr_employee.emp_lastname) as employeename FROM ohrm_project,ohrm_timesheet_item,hs_hr_employee WHERE  ohrm_timesheet_item.employee_id=hs_hr_employee.employee_id AND ohrm_timesheet_item.project_id=ohrm_project.project_id AND ohrm_project.project_id='.$projectid.' AND ohrm_timesheet_item.date BETWEEN '.$todate1.' AND '.$fromdate1.'');
        $this->load->dbutil();
$this->load->helper('download');
$this->load->helper('file');
$delimiter = ",";
$newline = "\r\n";
$filename = 'projectimesheet.csv';
if($searchtimesheet->num_rows() >0)
{
$totalduration1=$totalduration;  //i want to append this static value to $this->dbutil->csv_from_result
    echo $data = $this->dbutil->csv_from_result($searchtimesheet,$delimiter, $newline);
    exit;
    force_download($filename, $data);

}

1 个答案:

答案 0 :(得分:0)

您可以将$ totalduration变量值附加到结果中,如下所示:

echo $this->dbutil->csv_from_result($searchtimesheet, $delimiter, $newline) . $totalduration;

注意:$ totalduration变量应包含与获取有效CSV的结果相同的CSV数据字符串。