我是 codeigniter 的新手。我已经阅读了事件记录并完成了以下代码:
header("Content-Type: text/csv");
header("Content-Disposition: attachment; filename=file.csv");
header("Cache-Control: no-cache, no-store, must-revalidate"); // HTTP 1.1
header("Pragma: no-cache"); // HTTP 1.0
header("Expires: 0"); // Proxies
$output = fopen('php://output', 'w');
fputcsv($output, array('Column 1', 'Column 2', 'Column 3'));
$this->db->select('field_id_1, field_id_2, field_id_3');
$query = $this->db->get('exp_channel_data');
$rows = $query->result_array();
while ($row = mysql_fetch_assoc($rows)) fputcsv($output, $row);
在此代码块末尾的while
语句中,我不确定使用什么来代替mysql_fetch_assoc
。
我已将数据库结果输出到变量$rows
中。
应该用什么来替换while
语句中的mysql_fetch_assoc
?
谢谢。
最佳答案
当您使用 result_array() 时。因此 $rows 以数组形式给出结果,您可以使用 foreach 循环从 $rows 中提取数据,例如 foreach($rows as $row)。
关于php - 而不是 'mysql_fetch_assoc' - Codeigniter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27930773/