码迷,mamicode.com
首页 > 其他好文 > 详细

tp3.2导出csv

时间:2018-01-17 01:03:48      阅读:133      评论:0      收藏:0      [点我收藏+]

标签:绑定   friend   ignore   create   sele   account   gen   tp3.2   php   

function test(){
        $csv=new \Think\Csv();
        $sql = "SELECT count(ga.parentId) as friendnum,a.id,a.uuid,a.nickName,a.agentUserType,a.roomCard,a.createTime,a.lastTime,a.gold,a.parentId FROM t_account as a LEFT JOIN t_account as ga on a.uuid=ga.parentId WHERE ( 1=1 ) GROUP BY a.uuid ORDER BY createTime desc ";
        $list = M(‘account‘)->query($sql);  //数据
        $csv_title=array(‘好友数量‘,‘ID‘,‘UUID‘,‘昵称‘,‘用户类型‘,‘房卡数量‘,‘创建时间‘,‘更新时间‘,‘金币数量‘,‘绑定ID‘);  //字段
        $csv->put_csv($list,$csv_title);
     }

Csv.class.php

<?php
namespace Think;
class Csv
{
   //导出csv文件
   public function put_csv($list,$title){
       $file_name="CSV".date("Y-m-d",time()).".csv";
       header ( ‘Content-Type: application/vnd.ms-excel‘ );
       header ( ‘Content-Disposition: attachment;filename=‘.$file_name );
       header ( ‘Cache-Control: max-age=0‘ );
       $file = fopen(‘php://output‘,"a");
       $limit=1000;
       $calc=0;
       foreach ($title as $v){
//           $tit[]=iconv(‘UTF-8‘, ‘GB2312//IGNORE‘,$v);
           $tit[]=$v;
       }
       fputcsv($file,$tit);
       foreach ($list as $v){
           $calc++;
           if($limit==$calc){
               ob_flush();
               flush();
               $calc=0;
           }
           foreach ($v as $t){
//               $tarr[]=iconv(‘UTF-8‘, ‘GB2312//IGNORE‘,$t);
               $tarr[]=$t;
           }
           fputcsv($file,$tarr);
           unset($tarr);
       }
       unset($list);
       fclose($file);
       exit();
   }    

}

?>

 

tp3.2导出csv

标签:绑定   friend   ignore   create   sele   account   gen   tp3.2   php   

原文地址:https://www.cnblogs.com/csd97/p/8297778.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!