由於工作需要今天我們要把mysql數據庫裡面的數據導出到execel裡面用,後來在網上找了一下原來這麼簡單,因csv文件只要以"," 分開就OK了,下面我們就來看看實例吧.
<?php
include("../inc/connect.php");
$Date = date("Y-m-d");
$Filename = $Date.".csv";
$Table = isset($_GET['tid'])?$_GET['tid']:'';
header("Content-type:application/vnd.ms-excel");
header("Content-Disposition:filename=".$Filename);
echo "用戶名,真實姓名,聯系方式,聯系QQ,聯系地址,郵箱地址 rn";
$Sql = "Select * from gx_member where datediff(m_time,'".date("Y-m-d H:i:s")."')<=$Table order by id desc ";
$Result = mysql_query($Sql);
while($rs = mysql_fetch_array($Result) ){
echo $rs['m_name'].','. $rs['m_realname'].",". $rs['m_tel'].",". $rs['m_qq'].",". $rs['m_address'].",". $rs['m_mail']." rn ";
}
?>
上面我們用的是導出csv文件還有一種就導出xls文件只要修改一下
header("Content-type:application/vnd.ms-excel");
header("Content-Disposition:filename=".$Filename);
就差不多了.
本站原創轉載請注明www.111cn.cn/phper/php.html