Home > php教程 > php手册 > body text

php怎么把数据表中的数据导出到excel表中

WBOY
Release: 2016-05-25 16:38:21
Original
1506 people have browsed it

很多时候,数据库中的数据需要导出成excel,以下是最简便的方法,不用导出excel的类,即使功能简单,但是对于没有复杂需求的项目"见效快".

先定义头部信息,表示输出一个excel,然后再以table的形式把数据库的信息循环的echo出来,就好了,代码如下:

";
//导出表头(也就是表中拥有的字段)
while ($row = mysql_fetch_array($res)) {
    $t_field[] = $row['Field']; //Field中的F要大写,否则没有结果
    echo "" . $row['Field'] . "";
}
echo "";
//导出100条数据
$sql = "select * from users limit 100";
$res = mysql_query($sql);
while ($row = mysql_fetch_array($res)) {
    echo "";
    foreach ($t_field as $f_key) {
        echo "" . $row[$f_key] . "";
    }
    echo "";
}
echo "";
Copy after login


本文地址:

转载随意,但请附上文章地址:-)

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!