thinkphp exporting a large amount of data in CSV format

Source: Internet
Author: User

 Public functiontest2 () {$user _count= M (' department ')Count(); $page=Ceil($user _count/10000); $fp=fopen(' C:\file.csv ', ' W ');  for($p= 1;$p<=$page;$p++) {            $user= M (' Department ')->page ($p. ', 10000 ')Select (); foreach($user  as $fields) {                foreach($fields  as $i=$v) {                    $fields[$i] =Iconv(' Utf-8 ', ' GBK ',$v); } fputcsv ($fp,$fields); }            unset($user); }        fclose($fp); }

 Public functionExportseller ($begindate= ",$enddate= ",$areaid= 0,$search= ' ') {        Ini_set(' Memory_limit ', ' 1024M '); Set_time_limit(0 ); $where=Array();//Filter Criteria Collection        $areaid= Session (' authority ');//Area Manager role restricted viewing area//Select the start and end time to display the record        if(isset($_get[' Begindate ']) &&isset($_get[' EndDate '] )) {            $begindate= I (' get.begindate ' ); $enddate= I (' get.enddate ' ); $begindate. = "00:00:00"; $enddate. = "23:59:59"; $where[' r.createtime '] =Array (                ' Between ',Array (                    $begindate,$enddate                )            ); if(FALSE===Empty($_get[' Search '] )) {                $search= I (' Get.search ' ); $where[' i.user '] =Array (                    ' Like ', '% '.$search. ‘%‘                ); }            if($areaid> 0) {                $where[' s.id_area '] =$areaid; } ElseIf(FALSE===Empty($_get[' Areaid '] )) {                $areaid= I (' Get.areaid ' ); $where[' s.id_area '] =$areaid; } Else {            }            $record= D (' Record ' ); $xlsCell=Array(' comp ' = ' company ', ' sellername ' + ' name ', ' sellermobile ' = ' phone number ', ' sellerjob ' + ' jobs ', ' shopno ' + ' shop number ', ' Shopname ' + ' shop name ', ' areaname ' = ' market ', ' prodname ' and ' trade names ', ' Sellerjifen ' + ' points ', ' seltime ' + ' sales time ', ' Wuliu ' = ' + ' Logistic code ', ' JFCD ' + ' Integrator Code ', ' Card_num ' and ' bank card number ', ' fgoodscode ' + ' product number ', ' fgoodsname ' + ' product name ', ' Fbilldate ' + ' out-of-storage time ', ' fclientcode ' + ' dealer number ', ' fclientname ' = ' dealer name ', ' istoo ' and ' = ' match '); $list=$record->sellerreport ($where ); foreach($list  as $i=$row ) {                $webdata=m (' Webservicedata '); $map[' Box_code ']=Array(' eq ',$row[' Wuliu ']); $arr=$webdata->where ($map),find (); //$arr = $this->webserverdata ($row [' Wuliu ']);                $row[' fgoodscode '] =$arr[' Fgoodscode ']; $row[' fgoodsname '] =$arr[' Fgoodsname ']; $row[' fbilldate '] =$arr[' Fbilldate ']; $row[' fclientcode '] =$arr[' Fclientcode ']; $row[' fclientname '] =$arr[' Fclientname ']; $row[' istoo '] =$arr[' fclientcode '] = =$row[' Shopno ']? ' Match ': ' Mismatch '; $str[$i]=array_iconv ($row); }            Array_unshift($str, Array_iconv ($xlsCell)); Header("Content-type:application/vnd.ms-excel" ); Header("Content-disposition:filename=".Iconv("UTF-8", "GB18030", "Beautician statistics report".Date(' _ymdhis ')) . ". csv" ); $fp=fopen(' Php://output ', ' a '); foreach($str  as $key=$line) {fputcsv ($fp,$line); }            fclose($fp);//\admin\model\excelmodel::exportexcel (' Beautician Statistics Report ', $xlsCell, $list);        }         die(); //End Modify        $this-display (); }

thinkphp exporting a large amount of data in CSV format

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.