我有一个页面,显示所有具有过滤功能的数据库..过滤后我想下载到 excel 格式...我成功获取所有数据并 fwrite() 它..现在请解释我如何下载它到excel表
http://sms.weddingsplanner.co.in/all_inquiry.php这是我的页面,其中出现了 Excel 按钮。
<?php
include 'functions.php';
ob_start();
if($_POST['types'] == 'name') {
$query = "SELECT * FROM visitor_detail WHERE name='".$_POST['filter']."' ORDER BY id DESC ";
}
elseif($_POST['types'] == 'mobile') {
$query = "SELECT * FROM visitor_detail WHERE mobile='".$_POST['filter']."' ORDER BY id DESC ";
}
elseif($_POST['types'] == 'OccasionType') {
$query = "SELECT * FROM visitor_detail WHERE OccasionType='".$_POST['filter']."' ORDER BY id DESC ";
}
elseif($_POST['types'] == 'InquiryDate') {
$query="SELECT * FROM visitor_detail WHERE TodayDate between '".$_POST['From']."' and '".$_POST['TO']."' ORDER BY id DESC " ;
}
elseif($_REQUEST['types'] == 'OccasionDate') {
$que="SELECT * FROM visitor_detail WHERE date between '".$_REQUEST['From']."' and '".$_REQUEST['To']."' ORDER BY id DESC ";
}
else {
$query = "SELECT * FROM visitor_detail ORDER BY id DESC ";
}
$sql = mysql_query($query);
$line1="Id\tgender\tname\tmobile\taddress\temail\totherno\tzipcode\tOccasionType\tdate\tgue st\tdescription\tTodayDate\tauther\t";
$data="$line1\n";
$br = '<br>';
$fileName = "./my.txt";
$file = fopen($fileName, "w");
fwrite($file, $data."\n");
$i=1;
while($row = mysql_fetch_assoc($sql))
{
$line2=$i . "\t" . $row['gender'] . "\t" . $row['name'] . "\t" . $row['mobile'] . "\t" . $row['address'] . "\t" . $row['email'] . "\t" . $row['otherno'] . "\t" . $row['zipcode'] . "\t" . $row['OccasionType'] . "\t" . $row['date'] . "\t" . $row['guest'] . "\t" . $row['description'] . "\t" . $row['TodayDate'] . "\t" . $row['auther'] . "\t";
$data1=$line2.$br;
echo $data1;
fwrite($file, $data1);
$i++;
}
fclose($file);
?>