<?php Header ("Content-type:application/vnd.ms-excel"); Header ("Content-disposition:filename=xls_region.xls"); $cfg _dbhost = ' localhost '; $cfg _dbname = ' TestDB '; $cfg _dbuser = ' root '; $cfg _dbpwd = ' root '; $cfg _db_language = ' UTF8 '; End configuration Link Database $link = mysql_connect ($cfg _dbhost, $cfg _dbuser, $cfg _dbpwd); mysql_select_db ($cfg _dbname); Select Encoding Www.111Cn.net mysql_query ("Set names". $cfg _db_language); Users table $sql = "desc users"; $res = mysql_query ($sql); echo "<table><tr>"; Export the header (that is, the fields that are owned in the table) while ($row = Mysql_fetch_array ($res)) { $t _field[] = $row [' field ']; The F in field is capitalized, otherwise there will be no result echo "<th>". $row [' Field ']. " </th> "; } echo "</tr>"; Export 100 Data $sql = "SELECT * from users limit 100"; $res = mysql_query ($sql); while ($row = Mysql_fetch_array ($res)) { echo "<tr>"; foreach ($t _field as $f _key) { echo "<td>" $row [$f _key]. " </td> "; } echo "</tr>"; } echo "</table>"; ?> |