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

PHP export csv or xls file program_PHP tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-13 17:07:14
Original
1044 people have browsed it

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 of this Website
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template