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實(shí)現(xiàn)Excel數(shù)據(jù)的導(dǎo)入導(dǎo)出(全步驟詳細(xì)解析)
- php導(dǎo)入導(dǎo)出excel實(shí)例
- php中導(dǎo)出數(shù)據(jù)到excel時數(shù)字變?yōu)榭茖W(xué)計數(shù)的解決方法
- php將數(shù)據(jù)庫導(dǎo)出成excel的方法
- 使用PHPExcel實(shí)現(xiàn)數(shù)據(jù)批量導(dǎo)出為excel表格的方法(必看)
- PHP實(shí)現(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)出方法實(shí)例
- php 自定義函數(shù)實(shí)現(xiàn)將數(shù)據(jù) 以excel 表格形式導(dǎo)出示例
相關(guān)文章
Yii框架實(shí)現(xiàn)郵箱激活的方法【數(shù)字簽名】
這篇文章主要介紹了Yii框架實(shí)現(xiàn)郵箱激活的方法,基于郵箱發(fā)送郵件實(shí)現(xiàn)數(shù)字簽名的激活功能,需要的朋友可以參考下2016-10-10淺談使用 Yii2 AssetBundle 中 $publishOptions 的正確姿勢
本篇文章主要介紹了淺談使用 Yii2 AssetBundle 中 $publishOptions 的正確姿勢,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-11-11Yii2創(chuàng)建表單(ActiveForm)方法詳解
這篇文章主要介紹了Yii2創(chuàng)建表單(ActiveForm)的方法,結(jié)合實(shí)例形式詳細(xì)分析了Yii創(chuàng)建表單的詳細(xì)步驟及相關(guān)函數(shù)與屬性的使用技巧,需要的朋友可以參考下2016-07-07PHP執(zhí)行shell腳本運(yùn)行程序不產(chǎn)生core文件的方法
下面小編就為大家?guī)硪黄狿HP執(zhí)行shell腳本運(yùn)行程序不產(chǎn)生core文件的方法。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2016-12-12Zend Framework教程之Zend_Layout布局助手詳解
這篇文章主要介紹了Zend Framework教程之Zend_Layout布局助手用法,結(jié)合實(shí)例形式詳細(xì)分析了Layout布局的相關(guān)實(shí)現(xiàn)技巧,需要的朋友可以參考下2016-03-03