今天改一个微赞上的项目 导出人员列表 顺便会议一下当初的思路
代码如下
点击导出按钮 在site.php执行如下代码
public function dowebdown(){
header("Content-type:application/vnd.ms-excel");
header("Content-Disposition:filename=test.xls");
$sql = "SELECT * FROM ".tablename('weixin_luckuser');
$list = pdo_fetchall($sql);
//var_dump($list);
echo "<h1 align='center'>中奖名单</h1>";
echo "<table align='center' border=1 width='1300px' height='50px' cellpading=0 cellspacing=0>";
echo "<tr><td>微信昵称</td><td>真实姓名</td><td>奖项</td><td>奖品名称</td><td>中奖时间</td><td>领奖SN码</td><td>用户电话</td><td>用户部门</td></tr>";
foreach ($list as &$row){
$info = pdo_fetch("SELECT nickname,mobile,bumen,realname FROM ".tablename('weixin_flag')."WHERE openid = :openid ",array(':openid'=>$row['openid']));
//print_r($info);die;
$luckinfo = pdo_fetch("SELECT tag_name,luck_name FROM ".tablename('weixin_awardlist')." WHERE id = {$row['awardid']}");
$row['tag_name'] = $luckinfo['tag_name'];
$row['luck_name'] = $luckinfo['luck_name'];
$row['nickname'] = $info['nickname'];
$row['realname'] = $info['realname'];
$row['mobile'] = $info['mobile'];
$row['bumen'] = $info['bumen'];
echo "<tr>";
echo "<td>";
echo "{$row['nickname']}";
echo "</td>";
echo "<td>";
echo "{$row['realname']}";
echo "</td>";
echo "<td>";
echo "{$row['awardid']}";
echo "</td>";
echo "<td>";
echo "{$row['luck_name']}";
echo "</td>";
echo "<td>";
echo date("Y-m-d h:i:s","{$row['createtime']}");
echo "</td>";
echo "<td>";
echo "{$row['createtime']}";
echo "</td>";
echo "<td>";
echo "{$row['mobile']}";
echo "</td>";
echo "<td>";
echo "{$row['bumen']}";
echo "</td>";
echo "</tr>";
}
echo "</table>";
}
主要是头部的两行代码 : 这样就把一个数据导出来了 是不是很简单