php 带条件导出txt

  

<?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;

  

posted @ 2020-08-03 11:55  这该死的代码  阅读(332)  评论(0)    收藏  举报