<?php
$conn=mysql_connect('127.0.0.1','XXXXXX','XXXXXX');
mysql_select_db('XXXX',$conn);
mysql_query('SET NAMES "GBK"');
$arr=array();
if($_GET['action']=='form'){
$relust=mysql_query('select * from cxkj_diyform1 order by id desc',$conn);
while($row=mysql_fetch_assoc($relust)){
$arr[]=$row;
header("Content-Disposition:attachment;filename=".time().".xls");
echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><table><tr><th width="180">ID</th><th width="180">姓名</th><th width="180">邮箱</th><th width="180">电话</th><th width="180">地址</th><th width="280">内容</th></tr>';
foreach($arr as $v){
echo "<tr><td align='left'>".iconv('GBK','UTF-8',$v['id'])."</td><td align='left'>".iconv('GBK','UTF-8',$v['name'])."</td><td align='left'>".iconv('GBK','UTF-8',$v['email'])."</td><td align='left'>".iconv('GBK','UTF-8',$v['tel'])."</td><td align='left'>".iconv('GBK','UTF-8',$v['addr'])."</td><td align='left'>".iconv('GBK','UTF-8',$v['mess'])."</td></tr>";
}
echo '</table>';
}elseif($_GET['action']=='shop'){
$relust=mysql_query('select s.oid,s.price,s.ip,s.stime,s.cartcount,m.userid,m.uname,m.tel from cxkj_member as m,cxkj_shops_orders as s where s.userid=m.mid order by s.stime desc',$conn);
while ($row=mysql_fetch_assoc($relust)) {
$arr[]=$row;
}
header("Content-type:application/vnd.ms-excel");
header("Content-Disposition:attachment;filename=".time().".xls");
echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><table><tr><th width="180">订单号</th><th width="180">单价</th><th width="180">下单时间</th><th width="180">下单数量</th><th width="180">下单用户</th><th width="180">用户电话</th></tr>';
foreach ($arr as $v) {
echo "<tr>";
echo "<td>".iconv('GBK','UTF-8',$v['oid'])."</td>";
echo "<td>".iconv('GBK','UTF-8',$v['price'])."</td>";
echo "<td>".iconv('GBK','UTF-8',date('Y-m-d H:i:s',$v['stime']))."</td>";
echo "<td>".iconv('GBK','UTF-8',$v['cartcount'])."</td>";
echo "<td>".iconv('GBK','UTF-8',$v['uname'])."</td>";
echo "<td>".iconv('GBK','UTF-8',$v['tel'])."</td>";
echo "</tr>";
}
echo '</table>';
}
?>
$conn=mysql_connect('127.0.0.1','XXXXXX','XXXXXX');
mysql_select_db('XXXX',$conn);
mysql_query('SET NAMES "GBK"');
$arr=array();
if($_GET['action']=='form'){
$relust=mysql_query('select * from cxkj_diyform1 order by id desc',$conn);
while($row=mysql_fetch_assoc($relust)){
$arr[]=$row;
}
//数字太长会带E符号,想去掉的话加个样式即可,<td align='left' style='vnd.ms-excel.numberformat:@'>123154545213454</td>
header("Content-type:application/vnd.ms-excel");header("Content-Disposition:attachment;filename=".time().".xls");
echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><table><tr><th width="180">ID</th><th width="180">姓名</th><th width="180">邮箱</th><th width="180">电话</th><th width="180">地址</th><th width="280">内容</th></tr>';
foreach($arr as $v){
echo "<tr><td align='left'>".iconv('GBK','UTF-8',$v['id'])."</td><td align='left'>".iconv('GBK','UTF-8',$v['name'])."</td><td align='left'>".iconv('GBK','UTF-8',$v['email'])."</td><td align='left'>".iconv('GBK','UTF-8',$v['tel'])."</td><td align='left'>".iconv('GBK','UTF-8',$v['addr'])."</td><td align='left'>".iconv('GBK','UTF-8',$v['mess'])."</td></tr>";
}
echo '</table>';
}elseif($_GET['action']=='shop'){
$relust=mysql_query('select s.oid,s.price,s.ip,s.stime,s.cartcount,m.userid,m.uname,m.tel from cxkj_member as m,cxkj_shops_orders as s where s.userid=m.mid order by s.stime desc',$conn);
while ($row=mysql_fetch_assoc($relust)) {
$arr[]=$row;
}
header("Content-type:application/vnd.ms-excel");
header("Content-Disposition:attachment;filename=".time().".xls");
echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><table><tr><th width="180">订单号</th><th width="180">单价</th><th width="180">下单时间</th><th width="180">下单数量</th><th width="180">下单用户</th><th width="180">用户电话</th></tr>';
foreach ($arr as $v) {
echo "<tr>";
echo "<td>".iconv('GBK','UTF-8',$v['oid'])."</td>";
echo "<td>".iconv('GBK','UTF-8',$v['price'])."</td>";
echo "<td>".iconv('GBK','UTF-8',date('Y-m-d H:i:s',$v['stime']))."</td>";
echo "<td>".iconv('GBK','UTF-8',$v['cartcount'])."</td>";
echo "<td>".iconv('GBK','UTF-8',$v['uname'])."</td>";
echo "<td>".iconv('GBK','UTF-8',$v['tel'])."</td>";
echo "</tr>";
}
echo '</table>';
}
?>