先定义头部信息,表示输出一个excel。然后再以table的形式把数据库的信息循环的echo出来,就好了。
//链接数据库
$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条数据
$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>\";
?>
本文地址:https://www.stayed.cn/item/4603
转载请注明出处。
本站部分内容来源于网络,如侵犯到您的权益,请 联系我