标签:blog io os ar sp 文件 数据 div on
<?php date_default_timezone_set(‘PRC‘); $filename="info.xls";//先定义一个excel文件 header("Content-Type: application/vnd.ms-execl"); header("Content-Type: application/vnd.ms-excel; charset=utf-8"); header("Content-Disposition: attachment; filename=$filename"); header("Pragma: no-cache"); header("Expires: 0"); //我们先在excel输出表头,当然这不是必须的 echo iconv("utf-8", "gb2312", "编号")."\t"; echo iconv("utf-8", "gb2312", "姓名")."\t"; echo iconv("utf-8", "gb2312", "年龄")."\t"; echo iconv("utf-8", "gb2312", "性别")."\n";//注意这个要换行 //这里我们定义一个数据库为datebse 数据库用户名:root 密码为:123456 $conn = mysql_connect("localhost","root",""); mysql_select_db("thinkphp"); mysql_query("set names utf8"); //在这里我们定义一个名叫studen的表,她有id,name,age,sex四个字段 $sql="select id,name,age,sex from student"; $result=mysql_query($sql); while($row =mysql_fetch_array($result)){ echo iconv("utf-8", "gb2312", $row[‘id‘])."\t"; echo iconv("utf-8", "gb2312", $row[‘name‘])."\t"; echo iconv("utf-8", "gb2312", $row[‘age‘])."\t"; echo iconv("utf-8", "gb2312", $row[‘sex‘])."\n"; }
标签:blog io os ar sp 文件 数据 div on
原文地址:http://www.cnblogs.com/qisel/p/4031093.html