Problem with fputcsv. Inserting HTML code into csv file
I have problem with writing csv file using fputcsv. Its putting the page html also into the csv file. Whats wrong with my code ?
//Excel header
header("Content-Disposition: attachment; filename=\"Delivery_Reports.csv\";" );
header("Content-type: application/vnd.ms-excel");
$out = fopen("php://output", 'w');
$flag = false;
// $result = mysql_query("SELECT * FROM senderids ") or die('Query failed!');
//$sel="SELECT number as MobileNumber ,snum as Sender , msg as Subject ,crdate as Date ,status FROM savemsg WHERE userID='".$_SESSION['id']."' ".$str." ORDER BY sn DESC ";
$result = mysql_query("SELECT `count`, `dnd`, `credit`, `sender_id`, `to`, `message`, `status` FROM `reports` WHERE `unq_id` = '$dlr_id'");
while(false !== ($row = mysql_fetch_assoc($result))){
if(!$flag){
$list = array( "Total"=>"Total","DND"=>"DND","Credits"=>"Credits","From"=>"From","To"=>"To","Message"=>"Message","Status"=>"Status", );
// display field/column names as first row
fputcsv($out, array_keys($list), ',', '"');
$flag = true;
}
// array_walk($row, 'cleanData');
fputcsv($out, array_values($row), ',', '"');
}
fclose($out);
10 Months Ago
Last Updated
Related Article: Generate CSV file using PHP
is a PHP discussion thread by ashishrevar that has 1 reply, was last updated 7 months ago and has been tagged with the keywords: write, csv, files, through, php, code.
rayidi
Junior Poster in Training
83 posts since May 2011
Reputation Points: 13
Solved Threads: 3
Skill Endorsements: 0
Question Answered as of 10 Months Ago by
ddsuresh