将查询输出到 csv、codeigniter
我目前有一份报告,其中提供了用户 ID 号及其电子邮件地址,但我想将其制作在 CSV 文件中,而不是像我目前那样的表格和行。
这是我的控制器
function View_Email_E()
{
$data = array();
if($query = $this->report_model->View_Email_English())
{
$data['records'] = $query;
}
$data['main_content'] = 'view_all_email_english';
$this->load->view('includes/template', $data);
}
这是我的模型
function View_Email_English()
{
$query = $this->db->where(array('Dial_Up' => '0', 'Language' => 'English', 'Membership_Status' => 'Active'));
$query = $this->db->like('Email', '@');
$query = $this->db->get('Membership');
return $query->result();
}
由于某种原因,我的视图没有以代码模式显示,但它是使用这些代码片段自动生成的表。每行返回数据库中的 ID 和电子邮件。
<?php if(isset($records)) : foreach($records as $row) : ?>
如何制作仅包含 ID 和电子邮件字段的 CSV 文件?
谢谢
I currently have a report that give me the users ID number and their email address, But I would like to make this in a CSV file instead of tables and rows like I currently have.
Here is my controller
function View_Email_E()
{
$data = array();
if($query = $this->report_model->View_Email_English())
{
$data['records'] = $query;
}
$data['main_content'] = 'view_all_email_english';
$this->load->view('includes/template', $data);
}
Here is my model
function View_Email_English()
{
$query = $this->db->where(array('Dial_Up' => '0', 'Language' => 'English', 'Membership_Status' => 'Active'));
$query = $this->db->like('Email', '@');
$query = $this->db->get('Membership');
return $query->result();
}
For some reason my view is not being shown in code mode, but it is an auto generated table using these this snippet of code. Each row returns ID and Email from the database.
<?php if(isset($records)) : foreach($records as $row) : ?>
How can I make a CSV file with just ID and email fields?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为您可以使用 dbutil 中的 csv_from_result 函数来完成此操作。尝试这样的事情:
http://codeigniter.com/user_guide/database/utilities.html# .csv
I think you can use the csv_from_result function in dbutil to do it. Try something like this:
http://codeigniter.com/user_guide/database/utilities.html#csv
添加
到您的 View_Email_English 函数。
Add
To your View_Email_English function.