PHP implementation Export Data classification merge cell function

Source: Internet
Author: User

1<?PHP2     $conn=mysql_connect("localhost", "root", "root");3     $db=mysql_select_db("Imexcel",$conn);4     mysql_query("Set names ' GBK '");5 6     $query= "Select Danwei,count (danwei) as NUM, Group_concat (Fuze SEPARATOR ', ') as GW from ' dy ' Group by Danwei";7     $result=mysql_query($query);8     Header("CONTENT-TYPE:APPLICATION/VND.MS-EXCEL;CHARSET=GBK");9     Header("Content-disposition:filename=test.xls");Ten     Echo‘ One <table border= "1" > A <caption class= "Text-center" > Information tab </caption> - <thead> - <tr > the <th> units </th> - <th> Manager </th> - </tr> - </thead> + <tbody> -‘; +                 while($row=Mysql_fetch_array($result)) { A                    $GW=Explode(",",$row[' GW ']); at                    Echo‘ - <tr> -&LT;TD rowspan= "'.$row[' Num ']. ' " > '.$row[' Danwei ']. '</td> -<td> '.Iconv("GBK", "Utf-8",$GW[0]). '</td> - </tr> -‘; in                     if($row[' num '] > 1){ -                          for($i= 1;$i<$row[' Num '];$i++){ to                             Echo' <tr><td> '.Iconv("GBK", "Utf-8",$GW[$i]).‘ </td></tr> '; +                         } -}Else{ the  *                     } $ Panax Notoginseng                } -  the Echo‘ + </tbody> A </table> the‘; +?>
1 CREATE TABLE IF  not EXISTS' dy ' (2' ID 'int( One) unsigned not NULLAuto_increment,3' Danwei 'varchar( -) not NULL,4' Fuze 'varchar( -) not NULL,5   PRIMARY KEY(' id ')6) ENGINE=MyISAMDEFAULTCHARSET=GBK auto_increment=7 ;7 8 --9 --dump the data in the table ' dy 'Ten -- One  A INSERT  into' Dy ' (' id ', ' danwei ', ' fuze ')VALUES -(1,'a','Xiao Zhang'), -(2,'a','Xiao Sun'), the(3,'b','Xiao Wang'), -(4,'C','Xiao Li'), -(5,'a','Little Red'), -(6,'b','Xiao Zhao');

Feature Implementation preview:

PHP implementation Export Data classification merge cell function

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.