basically I am passing the selected values of dropdown menus present in form to the
export function I wrote in controller by using ajax call like this
$("body").on("click","#download", function(){
var f_id = $("#f_id").val();
var s_id = $("#s_id").val();
var t_id = $("#t_id").val();
$.ajax({
async:false,
url:"<?php echo site_url().'export/export_csv'?>/"+f_id+'/'+s_id+'/'+t_id,
success: function(response) {
//
}
});
});
after cicking download ,I am getting all the values correctly and also getting the data from mysql database using those values but at the end of function when fputcsv function get called like this
fputcsv($output, $data);
the file is downloading successfiully ,but In exported file only the headers are getting printed not the data I am getting in $data as an array which is required while exporting csv and print the data in file
This is my export_csv function in controller
public function export_csv($f_id,$s_id,$t_id){
$fileName = "Ex.csv";
// temporary creates file
$output = fopen('php://memory', 'w');
// for message headers
$csvHeaders = array(
'0' => array(
'0' => 'Colummn 1',
'1' => 'Column 2',
)
);
header('Content-Type: text/csv');
header('Content-Disposition: attachment; filename="' . $fileName . '";');
foreach ($csvHeaders as $value) {
fputcsv($output, $value);
fwrite($output, "\t" . "\r\n");
}
$details = $this->my_model->get_details($f_id,$s_id,$t_id);
foreach ($details as $data) {
fputcsv($output, $data);
fwrite($output, "\t" . "\r\n");
}
}
How can I fix this , please guide me ?