处理后没有下载CSV文件? [英] CSV file is not getting downloaded after processing ?
本文介绍了处理后没有下载CSV文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要从php和mysql生成一个CSV文件,以获取两个日期之间的数据。
这里是我的代码:
Hi,
I need to generate a CSV file from php and mysql for data between the two dates.
here is my code:
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:
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:
bet_date_excel.php:
<?php
error_reporting(0);
include("database.php");
$fromdate= $_GET['fromdate'];
$todate = $_GET['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文件正在显示。
有人对此有所了解吗?
I have used chrome's webtool also in which in network tab this php file is getting called is showing.
anyone have idea about it?
推荐答案
( function (){
( #btn_bet_date)。click( function (){
var fromdate =
("#btn_bet_date").click(function() { var fromdate =
( #fromdate)。val();
var todate =
("#fromdate").val(); var todate =
这篇关于处理后没有下载CSV文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文