Create a CSV File for a user in PHP

前端 未结 19 1877
故里飘歌
故里飘歌 2020-11-22 11:52

I have data in a MySQL database. I am sending the user a URL to get their data out as a CSV file.

I have the e-mailing of the link, MySQL query, etc. covered.

<
相关标签:
19条回答
  • 2020-11-22 12:32

    Hey It works very well....!!!! Thanks Peter Mortensen and Connor Burton

    <?php
    header("Content-type: application/csv");
    header("Content-Disposition: attachment; filename=file.csv");
    header("Pragma: no-cache");
    header("Expires: 0");
    
    ini_set('display_errors',1);
    $private=1;
    error_reporting(E_ALL ^ E_NOTICE);
    
    mysql_connect("localhost", "user", "pass") or die(mysql_error());
    mysql_select_db("db") or die(mysql_error());
    
    $start = $_GET["start"];
    $end = $_GET["end"];
    
    $query = "SELECT * FROM customers WHERE created>='{$start} 00:00:00'  AND created<='{$end} 23:59:59'   ORDER BY id";
    $select_c = mysql_query($query) or die(mysql_error());
    
    while ($row = mysql_fetch_array($select_c, MYSQL_ASSOC))
    {
        $result.="{$row['email']},";
        $result.="\n";
        echo $result;
    }
    

    ?>

    0 讨论(0)
提交回复
热议问题