gpt4 book ai didi

php - 将数组的所有行插入MySql表 - Codeigniter相关

转载 作者:行者123 更新时间:2023-11-29 07:58:04 25 4
gpt4 key购买 nike

我正在尝试输入 100 个电子邮件地址,以“;”分隔并将它们存储在 MySql 表中。到目前为止我尝试过的是:

    $recipient_raw = $this->input->post('recipient'); //get the 100 emails in $recipient_raw
$recipient_array=explode(';', $recipient_raw); //explode them into an array
$title = $this->input->post('title');
$body = $this->input->post('body');

foreach($recipient_array->result() as $row):
$recipient=array(
'email'=>$row->email //looping through each email; seems I should not use $row->email since there's no title for them
);

$this->db->insert('eamil_send',$this->db->escape($recipient));
endforeach;

我在 CodeIgniter PHP 上运行它。错误消息位于 foreach($recipient_array->result() as $row): 行,其中显示:在非对象上调用成员函数 result()

如有任何建议,我们将不胜感激!谢谢!

最佳答案

result(),是一个用于转换数据库结果对象的事件记录函数。您正在创建一个标准数组。

$batch = array();
foreach($recipient as $row){
$batch[] = array(
'email' => $row
);
}
$this->db->insert_batch('email_send', $batch);

这应该可以完成您想要完成的任务。

关于php - 将数组的所有行插入MySql表 - Codeigniter相关,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24582190/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com