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:
<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= $_GET['fromdate'];
$todate = $_GET['todate'];
$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";
header("Content-type: application/vnd.ms-excel");
header("Content-disposition: csv" . date("Y-m-d") . ".csv");
header("Content-disposition: filename=".$filename.".csv");
echo "\n "." Report of FirstLook Preview";
print $out;
?>
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?