when send email using following code, works fine.
public function select() { $this->load->library('email', array('mailtype' => 'html')); $this->email->from('test@test.com','abc'); $this->email->to('test1@test.com'); $this->email->subject('test subject'); $message = "hello"; $this->email->message($message); if($this->email->send()) { $data["msg"] = "email has been sent."; $this->load->view("view_test", $data); } else { $data["msg"] = "email sending failed."; $this->load->view("view_test", $data); } }
but when want select 2 users id , send them emails not work. please check code below , me find mistake.
model
public function did_select() { $this->db->select('email, name'); $this->db->from('users'); $this->db->where('user_id', 5); $this->db->where('user_id', 11); $query = $this->db->get(); if ($query && $query->num_rows() > 0) { return $query->result_array(); } else { return false; } }
controller:
public function select() { if ($this->model_admin->did_select()) { foreach ($query->result_array() $row) { $name = $row['name']; $email = $row['email']; $this->load->library('email', array('mailtype' => 'html')); $this->email->from('test@test.com','abc'); $this->email->to($email); $this->email->subject($name.'test subject'); $message = "hello"; $this->email->message($message); if($this->email->send()) { $data["msg"] = "email has been sucessfully sent."; $this->load->view("view_test", $data); } else { $data["msg"] = "email sending failed."; $this->load->view("view_test", $data); } } } }
the problem 2 lines
$this->db->where('user_id', 5); $this->db->where('user_id', 11);
this produces query like
where user_id=5 , user_id=11
which not want. should replace second line with
$this->db->or_where('user_id', 11);
also maybe should remove view loading outside foreach
loop.
Comments
Post a Comment