Home  >  Article  >  Backend Development  >  PHP export csv or xls file program_PHP tutorial

PHP export csv or xls file program_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 17:07:14952browse

Due to work needs, today we have to export the data in the mysql database to execel for use. Later, I searched on the Internet and found out that it is so simple, because the csv file only needs to be separated by ",". Next we will Let’s take a look at an example.

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 "Username, real name, contact information, contact QQ, contact address, email address 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 ";
}

?>

What we used above is to export csv files. There is another way to export xls files. Just modify it

header("Content-type:application/vnd.ms-excel");
header("Content-Disposition:filename=".$Filename);

That’s it.

Please indicate www.111cn.cn/phper/php.html for original reprints on this site

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/630431.htmlTechArticleDue to work needs, today we have to export the data in the mysql database to execel for use. Later, I searched it online It turns out that it is so simple, because the csv file only needs to be separated by,. Next I...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn