Hi - I have an interesting result. We are on Codeigniter 3.1.11. I am running a query with a join, and the field that I'm using to join is returned twice in the list_fields() call but only once in the result_array().
Is this expected? I'm writing a CSV with headers and now there's an extra column which has no data.
This is my code:
Code:
$fullQry = "SELECT * FROM tblProgram O1 JOIN (SELECT `pkProgramID`
FROM `tblProgram`
JOIN `tblPlots` ON `tblPlots`.`programID`=`tblProgram`.`pkProgramID`
JOIN `tblTrees` ON `tblTrees`.`_nefin_plotID`=`tblPlots`.`_nefin_plotID`
GROUP BY `pkProgramID`) AS O2 ON O1.pkProgramID=O2.pkProgramID GROUP BY O1.pkProgramID";
$resultsALL= $this->db->query($fullQry);
$fields=$resultsALL->list_fields();
$resultArray=$resultsALL->result_array();
//open filestream for program data
$program_handle=fopen($programPath,'a');
if (!$program_handle){
show_error('could not open hand for program data');
}
//put headers into CSV
fputcsv($program_handle, $programData['fields']);
//put data into CSV
foreach ($programData['data'] as $line) {
fputcsv($program_handle, $line, ',', '"' , '');
}
fclose($program_handle);