导出符合条件的mysql记录

view层code:

导出所有数据

controller层code:

/**
* 生成EXCEL文件
*/
public function action_export_excel()
{
$status = $_REQUEST['status'];
header("Content-type:application/vnd.ms-excel");
header("Content-Disposition:filename=order.xls");
$card = $this->model_package->list_package_all($status);
echo "日期\t";
echo "用户名\t";
echo "购买金额\t";
echo "支付方式\t";
echo "支付状态\t";
echo "姓名\t";
echo "邮编\t";
echo "详细地址\t";
echo "所在单位\t";
echo "手机号\t";
echo "QQ\t";
echo "E-mail\t\n";
foreach($card as $value)
{
$date = date('Y-m-d H:i:s',$value['dateline']); 
$status = ($value['status']==1) ? '已支付' : '未支付';
echo "$date\t";
echo $value['user_name']."\t";
echo $value['money']."\t";
$bank = '';
if($value['payment']=='alipay')
{
$bank = '支付宝';  
}
elseif($value['payment']=='jkb')
   {
$bank = '建康币';
}
elseif($value['payment'] == 'chinabank')
{
$bank = '网上银行' . '(' . $value['bank'] . ')';
}
echo "$bank\t";
echo "$status\t";
echo $value['real_name']."\t" ;
echo $value['zip']."\t";
echo $value['addr']."\t";
echo $value['unit']."\t";
echo $value['phone']."\t";
echo $value['qq']."\t";
echo $value['mail']."\t\n";
}
}

model层code:

   /*
     * 全部套餐卡列表
     */
    public function list_package_all($status)
    {
    $status = intval($status);
    if($status==0)
    {
    $sql   = "select p.payment,p.dateline,p.bank,u.user_name,u.real_name,uf.addr,uf.unit,uf.qq,uf.mail,uf.phone,uf.zip,o.status,o.money from {$this->prefix}package_order o left join {$this->prefix}user u on o.uid=u.uid left join {$this->prefix}user_fields uf on u.uid=uf.uid left join {$this->prefix}package p on o.package_id=p.id order by o.id desc";
    }
    else
    {
        $sql   = "select p.payment,p.dateline,p.bank,u.user_name,u.real_name,uf.addr,uf.unit,uf.qq,uf.mail,uf.phone,uf.zip,o.status,o.money from {$this->prefix}package_order o left join {$this->prefix}user u on o.uid=u.uid left join {$this->prefix}user_fields uf on u.uid=uf.uid left join {$this->prefix}package p on o.package_id=p.id where o.status = 1 order by o.id desc";
    }
        $card  = $this->db->query(Database::SELECT, $sql,FALSE)->as_array();
        return $card;
    }

你可能感兴趣的:(php)