PHP export CSV or XLS file program _php Tutorial

Source: Internet
Author: User
Because the work needs today we want to export the data inside the MySQL database into Execel, and later found on the internet so simple, because the CSV file as long as the "," separate is OK, below we will take a look at the example bar.

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 "User name, real name, contact information, contact QQ, contact address, e-mail 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";
}

?>

We used to export the CSV file and a kind of export XLS file as long as modified

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

It's almost over.

This site original reprint please specify www.111cn.cn/phper/php.html

http://www.bkjia.com/PHPjc/630431.html www.bkjia.com true http://www.bkjia.com/PHPjc/630431.html techarticle because the work needs today we want to export the data inside the MySQL database into Execel, and later found on the internet so simple, because the CSV file as long as, separate OK, below I ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.