我将数据从mysql导出到excel,在codeigniter中它在localhost上工作正常 但它不能在服务器.on服务器上工作,它只打印这样的数组。
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
)
答案 0 :(得分:0)
<?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);
?>
答案 1 :(得分:0)
确定它在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');
和bingo