atortega
10-26-2004, 11:03 PM
Hi!
I have some problems when exporting my database records.
1. I want it to have a file extension of ".csv" but in my local server it always gives an ".xls" extension (ex: csv20051027.xls)"
2. When I uploaded the code to the live server, it give me a different filename with no file extension (ex: export_php).
By the way, filename of the code is export.php.
What seems to be the problem of the code?
Below is part of the code.
$csv_output = "story_id, user_id, transaction_num, lastFour, res_change, story_role, partner_fname, partner_minitial, partner_lname, partner_relationship, partner_other, partner_email, res_date, time_slot, kiosk_id, questions, pay_date, promo_code, billingAddress, billingCity, billingState, billingZip, res_type, lastmodified, lastuser";
$csv_output .= "\r\n";
$result = mysql_query("select * from myData");
$fc = mysql_num_fields( $result );
while($row = mysql_fetch_array($result))
{
for( $i=0; $i < $fc; $i++ )
{
if( $i!=0 ) $csv_output .= ",";
$csv_output .= "$row[$i]";
}
$csv_output .= "\r\n";
}
header("Content-disposition: filename=\"csv" . date("Ymd") . ".csv\"");
header("Content-type: application/vnd.ms-excel");
print $csv_output;
exit;
I have some problems when exporting my database records.
1. I want it to have a file extension of ".csv" but in my local server it always gives an ".xls" extension (ex: csv20051027.xls)"
2. When I uploaded the code to the live server, it give me a different filename with no file extension (ex: export_php).
By the way, filename of the code is export.php.
What seems to be the problem of the code?
Below is part of the code.
$csv_output = "story_id, user_id, transaction_num, lastFour, res_change, story_role, partner_fname, partner_minitial, partner_lname, partner_relationship, partner_other, partner_email, res_date, time_slot, kiosk_id, questions, pay_date, promo_code, billingAddress, billingCity, billingState, billingZip, res_type, lastmodified, lastuser";
$csv_output .= "\r\n";
$result = mysql_query("select * from myData");
$fc = mysql_num_fields( $result );
while($row = mysql_fetch_array($result))
{
for( $i=0; $i < $fc; $i++ )
{
if( $i!=0 ) $csv_output .= ",";
$csv_output .= "$row[$i]";
}
$csv_output .= "\r\n";
}
header("Content-disposition: filename=\"csv" . date("Ymd") . ".csv\"");
header("Content-type: application/vnd.ms-excel");
print $csv_output;
exit;