I have name,address and images stored in my database.on clicking "GENERATE EXCEL" button a .csv file will be generated.I am using comma as a separator.
my actual o/p should be like this:
name address images
peter "house no#2",uk img1.png,img2.png,img3.png
but currently i am getting the values with comma in different columns.how can i do this? please help.
this is my code fetching the values from the database:
$sep = ",";
$csv_hdr = "Name".$sep."Address".$sep."Images";
$csv_output="";
for($i=$start;$i<$match;$i++)
{
$csv_output .=$ARRAY[$i]['source_name'].$sep;
$i_add=str_replace('"',"",$ARRAY[$i]['source_address']);
$csv_output.=$ARRAY[$i]['source_address'].$sep;
$csv_output.=$ARRAY[$i]['source_img']."\n";
}
this is my 'GENERATE_EXCEL' button with 2 hidden fields csv header and data.
<div id="btnexcel">
<input type="submit" name="Generate Excel" value="Generate Excel" id="btnreport" formaction="export_to_excel.php"/></div>
<input type="hidden" value="<?php echo $csv_hdr; ?>" name="csv_hdr">
<input type="hidden" value="<?php echo $csv_output; ?>" name="csv_output">
this is my export_to_excel.php:
<?php
$out = '';
$filename_prefix = 'csv';
if (isset($_GET['csv_hdr'])) {
$out .= $_GET['csv_hdr'];
$out .= "\n";
}
if (isset($_GET['csv_output'])) {
$out .= $_GET['csv_output'];
}
$filename = $filename_prefix."_".date("Y-m-d_H-i",time());
//Generate the CSV file header
header("Content-type: application/vnd.ms-excel");
header("Content-Encoding: UTF-8");
header("Content-type: text/csv; charset=UTF-8");
header("Content-disposition: csv" . date("Y-m-d") . ".csv");
header("Content-disposition: filename=".$filename.".csv");
echo "\xEF\xBB\xBF"; // UTF-8 BOM
//Print the contents of out to the generated file.
print $out;
//Exit the script
exit;
?>