[英]I have some record in mysql database .I want to export daily record in csv file format using php?
this is how i use mysql to get CSV export.If you have better code then suggest me 这就是我使用mysql获取CSV export.If你有更好的代码然后建议我
while( $row = mysql_fetch_row( $export ) ) {
$line = '';
foreach( $row as $value ) {
if ( ( !isset( $value ) ) || ( $value == "" ) ){
$value = ",";
}
else {
$value = str_replace( '"' , '""' , $value );
$value = '"' . $value . '"' . ",";
}
$line .= $value;
}
$data .= trim( $line ) . "\n";
}
$data = str_replace( "\r" , "" , $data );
$date = date ("Y-m-d", strtotime("+1 day", strtotime($date)));
}
header("Content-type: application/vnd.ms-excel");
header("Content-disposition: csv" . date("Y-m-d") . ".csv");
header( "Content-disposition: filename=".$file_name.".csv");
print "$header\n$data";
exit;
?>
Please give me the solution 请给我解决方案
PHP has a fputcsv function you can use for these purposes: PHP具有fputcsv函数,可以将其用于以下目的:
http://php.net/manual/en/function.fputcsv.php http://php.net/manual/en/function.fputcsv.php
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.