转自:https://blog.csdn.net/chihouzi/article/details/107717121
<?php
//带条件导出
$wherelist = array();
if (!empty($_GET['status'])) {
$wherelist[] = " status =".$_GET['status'];
}
if (!empty($_GET['message'])) {
$wherelist[] = " phone like '%".$_GET['message']."%'";
}
if (count($wherelist) > 0) {
$where = " where ".implode('and ', $wherelist);
}
include('../common/mysqlconf.php');
$sql = "select id,phone,add_time,if(status=0,'未通过','已通过') status from user_partake $where";
$result = mysql_query($sql, $conn);
$totalnum = mysql_num_rows($result);
if (empty($totalnum)) {
echo "<script language=javascript>alert('没有要导出的数据');window.top.location.href='user_phone.php';</script>";
die;
}
$content = '';
while ($res=mysql_fetch_assoc($result)){
$content .= 'id:' . $res['id'] . ' -- 电话:' . $res['phone'] . ' -- 状态:' . $res['status'] . ' -- 时间:' . $res['add_time'] . "\r\n";
}
header("Content-type:application/octet-stream");
header("Accept-Ranges:bytes");
header("Content-Disposition:attachment;filename=".'手机号列表_'.date("YmdHis").".txt");
header("Expires:0");
header("Cache-Control:must-revalidate,post-check=0,pre-check=0 ");
header("Pragma:public");
echo $content;
© 版权声明
文章版权归作者所有,未经允许请勿转载。