处理后没有下载CSV文件?

时间:2014-12-20 12:30:49

标签: php mysql excel csv

我需要从php和mysql生成一个CSV文件,以获取两个日期之间的数据。 这是我的代码:

From date: <input type="text" id="fromdate" value="" onChange="showuser()">   To date: <input type="text" id="todate" value="" onChange="showuser()">  <input type="button" id="btn_bet_date" value="Export in excel">

的Ajax:

<script type="text/javascript">
 $(function() {
                $("#btn_bet_date").click(function() {
                    var fromdate = $("#fromdate").val();
                     var todate = $("#todate").val();
                    $.post('bet_date_excel.php', { fromdate: fromdate,todate:todate });
                    return false;
                });
            });
</script>

bet_date_excel.php:

<?php
error_reporting(0);
  include("database.php");


    $fromdate= $_POST['fromdate'];
    $todate = $_POST['todate'];
//First we'll generate an output variable called out. It'll have all of our text for the CSV file.
$out = '';

 $csv_hdr .= "\n\n\n Id,Date,Time,Movie,Name,Email,Phone,Approved";

 $out .= $csv_hdr;

 $result1 = mysql_query("SELECT * from bookings where date between '$fromdate' and '$todate'");

 while($row = mysql_fetch_array($result1))
            {
                 $id= $row["id"];
                 $date= $row["date"];
                 $time= $row["time"];
                 $movie= $row["movie"];
                 $name= $row["name"];
                 $email= $row["email"];
                 $phone= $row["phone"];
                 $approved= $row["approved"];
            }
             $csv_output .= $id .", ".$date.", ".$time.", ".$movie.", ".$name.", ".$email.", ".$phone.", ".$approved;

$filename = "FirstLook-$fromdate-$todate";

//Generate the CSV file header

header("Content-type: application/vnd.ms-excel");
header("Content-disposition: csv" . date("Y-m-d") . ".csv");
header("Content-disposition: filename=".$filename.".csv");

//Print the contents of out to the generated file.
echo "\n                                                               "." Report of FirstLook Preview"; 

print $out;

?>

我已经使用了chrome的webtool,其中在网络标签中显示这个php文件正在显示。

谁知道呢?

0 个答案:

没有答案