繁体   English   中英

从Codeigniter中的mysql导出excel中的数据

[英]export data in excel from mysql in codeigniter

我正在将数据从mysql导出到codeigniter中的excel,它在localhost上运行良好,但在服务器上不起作用。在服务器上它仅打印这样的数组。

Array
(
    [0] => Array
        (
            [id] => 135
            [type] => 3
            [product_service] => 
            [email] => bewcontrols@gmail.com
            [first_name] => gurwinder sigh
            [last_name] => 
            [company_name] => 
            [country] => 
            [state] => 
            [city] => 
            [phone_number] => 91-011-09971587701
            [mobile] => 09971587701
            [fax_number] => 
            [address] => f-127 mayapuri indl area phase2 new delhi
            [zipcode] => 
            [message] => Subject: Fwd to purchase/ maint. for repairing of SOLENOID VALVE and PNEUMATIC cylinders ,DELHI,BHUPINDER ENGG.

Dear Sir,

I'd like to take this opportunity to introduce BEW Pneumatic
Controls,Delhi, to you.

We manufacture Heavy Duty Solenoid Valves in   Spool construction
using all-Aluminium fittings.While most manufacturers use plastic
fittings,plastic cages, we at BEW pioneered Aluminium fittings and
have incorporated them across our product line.

Please find attached our latest product catalogue for your perusal and
we look forward to hearing from you soon.

Best Regards,

Gurwinder Singh
Mobile-09811019362,
     and 09971587701

        [status] => 1
        [reply_status] => N
        [receive_date] => 2014-11-16 18:22:06
        [order_quantity] => 
    )

[1] => Array
    (
        [id] => 134
        [type] => 3
        [product_service] => 
        [email] => mohamed@gmail.com
        [first_name] => mohamed
        [last_name] => 
        [company_name] => 
        [country] => 
        [state] => 0
        [city] => 
        [phone_number] => 
        [mobile] => 9944556611
        [fax_number] => 
        [address] => 
        [zipcode] => 
        [message] => jhkhjh
        [status] => 1
        [reply_status] => N
        [receive_date] => 2014-11-11 15:42:47
        [order_quantity] => 20
    )
<?php


// output headers so that the file is downloaded rather than displayed
header('Content-Type: text/csv; charset=utf-8');
header('Content-Disposition: attachment; filename=filename.csv');

// create a file pointer connected to the output stream
$output = fopen('php://output', 'w');

// output the column headings
//fputcsv($output, array('Column 1', 'Column 2', 'Column 3'));

// fetch the data
mysql_connect('localhost', 'user', 'pass');
mysql_select_db("database");
$rows = mysql_query('SELECT something, something, something FROM table');

// loop over the rows, outputting them
while ($row = mysql_fetch_assoc($rows)) fputcsv($output, $row);

?>

好的,在CI中很简单只需下载csv库,然后

 $this->db->select('*')->from('yourtabl')->where(array('your_conditions')); 
 $query = $this->db->get();
$this->load->helper('csv');
   query_to_csv($query, TRUE, 'yourfilename.csv');

和宾果游戏

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM