急需 php+mysql网站,后台如何将数据库中的一个表导出到EXCEL文件,然后可以保存到本地!

2024-11-26 02:45:34
推荐回答(2个)
回答1:

//$result 是你数据库里的数据 ,下面的代码就可以直接用 很简单的 ,不明白的直接问我就好了

header("Content-Type: application/vnd.ms-excel; charset=UTF-8");
header("Content-Disposition: attachment; filename=ABC_Users.xls");
header("Pragma: no-cache");
header("Expires: 0");

echo iconv("utf8","gb2312","用户id\t");
echo iconv("utf8","gb2312","用户名\t");
echo iconv("utf8","gb2312","手机\t\n");
foreach($result as $key=>$val){\
echo iconv("utf8","gb2312",$val['id'])."\t";
echo iconv("utf8","gb2312",$val['name'])."\t";
echo iconv("utf8","gb2312",$val['mobile'])."\t\n";
}

回答2:

下载一个PHPMYADMIN 装到服务器上就行了,想怎么导怎么导。