php把數(shù)據(jù)表導出為Excel表的最簡單、最快的方法(不用插件)
先定義頭部信息,表示輸出一個excel。然后再以table的形式把數(shù)據(jù)庫的信息循環(huán)的echo出來,就好了。
<?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 配置
//鏈接數(shù)據(jù)庫
$link = mysql_connect($cfg_dbhost,$cfg_dbuser,$cfg_dbpwd);
mysql_select_db($cfg_dbname);
//選擇編碼
mysql_query("set names ".$cfg_db_language);
//users表
$sql = "desc users";
$res = mysql_query($sql);
echo "<table><tr>";
//導出表頭(也就是表中擁有的字段)
while($row = mysql_fetch_array($res)){
$t_field[] = $row['Field']; //Field中的F要大寫,否則沒有結果
echo "<th>".$row['Field']."</th>";
}
echo "</tr>";
//導出100條數(shù)據(jù)
$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>";
?>
- 利用phpExcel實現(xiàn)Excel數(shù)據(jù)的導入導出(全步驟詳細解析)
- php導入導出excel實例
- php中導出數(shù)據(jù)到excel時數(shù)字變?yōu)榭茖W計數(shù)的解決方法
- php將數(shù)據(jù)庫導出成excel的方法
- 使用PHPExcel實現(xiàn)數(shù)據(jù)批量導出為excel表格的方法(必看)
- PHP實現(xiàn)導出帶樣式的Excel
- php導出excel格式數(shù)據(jù)問題
- php導出word文檔與excel電子表格的簡單示例代碼
- php原生導出excel文件的兩種方法(推薦)
- PHP將Excel導入數(shù)據(jù)庫及數(shù)據(jù)庫數(shù)據(jù)導出至Excel的方法
- php中通用的excel導出方法實例
- php 自定義函數(shù)實現(xiàn)將數(shù)據(jù) 以excel 表格形式導出示例
相關文章
CI(CodeIgniter)框架實現(xiàn)圖片上傳的方法
這篇文章主要介紹了CI(CodeIgniter)框架實現(xiàn)圖片上傳的方法,結合實例形式分析了基于CodeIgniter調(diào)用文件上傳類實現(xiàn)圖片上傳功能的相關操作技巧,需要的朋友可以參考下2017-03-03
PHP微信開發(fā)之根據(jù)用戶回復關鍵詞\位置返回附近信息
這篇文章主要為大家詳細介紹了PHP微信開發(fā)之簡單實現(xiàn)根據(jù)用戶回復關鍵詞\位置返回附近信息 ,感興趣的小伙伴們可以參考一下2016-06-06

