我有一個頁面,顯示所有數據庫的過濾器功能..和過濾器後,我想下載到excel甲酸...我sucessfull獲取所有的數據和fwrite()它..現在請解釋我怎麼下載到Excel工作表
http://sms.weddingsplanner.co.in/all_inquiry.php部份是我的網頁上EXCELL按鈕出現..
<?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);
?>
你只是想知道如何下載CSV文件(擺脫回波,併發送相應的報頭)或如何創建一個真正的Excel文件? – 2013-03-14 11:45:21
我假定你的意思是[CSV](http://en.wikipedia.org/wiki/Comma-separated_values)文件。如果是這樣,你有[fputcsv](http://php.net/manual/en/function.fputcsv.php) – juco 2013-03-14 11:45:45