I'm trying to update a column in the MySQL table by using CodeIgniter's "update" active record. However, I can only update the first row of the array I put in. What am I doing wrong?
Code:
$invalid_email_raw='[email protected];
[email protected];
[email protected];
[email protected]';
$invalid_email=explode(';', $invalid_email_raw);
foreach ($invalid_email as $email):
$data=array(
'status'=>'unsubscribed'
);
$this->db->where('email', $email);
$this->db->update('user', $data);
endforeach;
Essentially, the code breaks the 4 emails into an array, and uses foreach to update the corresponding status where the email is found.
However, only the status for "[email protected]" is updated. All the other 3 are unchanged.
What am I doing wrong?
Parag Tyagianswer below. This is how you do it. It also executes faster. - machineaddict