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> -<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