php把數(shù)據(jù)表導(dǎo)出為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>";
//導(dǎo)出表頭(也就是表中擁有的字段)
while($row = mysql_fetch_array($res)){
$t_field[] = $row['Field']; //Field中的F要大寫,否則沒有結(jié)果
echo "<th>".$row['Field']."</th>";
}
echo "</tr>";
//導(dǎo)出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ù)的導(dǎo)入導(dǎo)出(全步驟詳細(xì)解析)
- php導(dǎo)入導(dǎo)出excel實例
- php中導(dǎo)出數(shù)據(jù)到excel時數(shù)字變?yōu)榭茖W(xué)計數(shù)的解決方法
- php將數(shù)據(jù)庫導(dǎo)出成excel的方法
- 使用PHPExcel實現(xiàn)數(shù)據(jù)批量導(dǎo)出為excel表格的方法(必看)
- PHP實現(xiàn)導(dǎo)出帶樣式的Excel
- php導(dǎo)出excel格式數(shù)據(jù)問題
- php導(dǎo)出word文檔與excel電子表格的簡單示例代碼
- php原生導(dǎo)出excel文件的兩種方法(推薦)
- PHP將Excel導(dǎo)入數(shù)據(jù)庫及數(shù)據(jù)庫數(shù)據(jù)導(dǎo)出至Excel的方法
- php中通用的excel導(dǎo)出方法實例
- php 自定義函數(shù)實現(xiàn)將數(shù)據(jù) 以excel 表格形式導(dǎo)出示例
相關(guān)文章
php設(shè)計模式之觀察者模式實例詳解【星際爭霸游戲案例】
這篇文章主要介紹了php設(shè)計模式之觀察者模式,結(jié)合星際爭霸游戲案例形式分析了php觀察者模式相關(guān)概念、原理、用法與操作注意事項,需要的朋友可以參考下2020-03-03
CI(CodeIgniter)框架實現(xiàn)圖片上傳的方法
這篇文章主要介紹了CI(CodeIgniter)框架實現(xiàn)圖片上傳的方法,結(jié)合實例形式分析了基于CodeIgniter調(diào)用文件上傳類實現(xiàn)圖片上傳功能的相關(guān)操作技巧,需要的朋友可以參考下2017-03-03
PHP微信開發(fā)之根據(jù)用戶回復(fù)關(guān)鍵詞\位置返回附近信息
這篇文章主要為大家詳細(xì)介紹了PHP微信開發(fā)之簡單實現(xiàn)根據(jù)用戶回復(fù)關(guān)鍵詞\位置返回附近信息 ,感興趣的小伙伴們可以參考一下2016-06-06
ThinkPHP中html:list標(biāo)簽用法分析
這篇文章主要介紹了ThinkPHP中html:list標(biāo)簽用法,較為詳細(xì)的分析總結(jié)了ThinkPHP中html:list標(biāo)簽的定義、使用方法及相關(guān)注意事項,需要的朋友可以參考下2016-01-01

