简体   繁体   English

我在mysql数据库中有一些记录。我想使用php以csv文件格式导出每日记录?

[英]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.

相关问题 如何使用php删除数据库中的记录? 我有一些代码正在删除,但它不会删除记录 - How to delete a record in database using php? I have some of my codes in deleting but it won't delete the record 我想将一些图片文件上传到我的服务器并将文件名记录在 mysql 数据库中但不知何故存在问题 - I want to upload some picture files to my server and record the file name in mysql database but somehow there exists a problem 我有这个php / mysql / ajax代码,我想在记录显示时添加淡入效果 - I have this php/mysql/ajax code and I want to add a fade in effect when the record show up 我想显示1条记录,而不是显示整个数据库,PHP - I want to display 1 record instead of displaying the whole Database, PHP 当日期将使用php过期时,我想向用户隐藏(数据库的)记录的详细信息 - I want to hide the details of record (of database) from user when date will be expired using php 我想从 mysql 中的 2 个不同表导出数据并转换为 csv 可能使用 php - I want to export data from 2 different tables in mysql and convert to csv maybe using php 我想使用MySQL LIMIT在分页中显示每页2条记录, - I want to show 2 record per page in Pagination using MySQL LIMIT, 如何在laravel中使用join来获取多个记录,我有多个记录,并且我想要该记录group_concat来获取 - how to fetch multiple record with using join in laravel i have multiple record and i want that record group_concat fetch 我想删除数据库中的记录使用php我点击哪条记录 - i want to delete the record from data base using php on which record i click 使用php从mysql数据库导出csv文件 - export a csv file from the mysql database using php
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM