I have the following code to remove user accounts that have not verified their email address within one week. The query works as I expect, but the delete function only deletes the first record, and I cant figure out why. The print_r generates the full results as I expect, but the delete function is somehow ignored. Any ideas on how to make it so it deletes all relevant records?
public function databaseupdate () //REMOVES ALL UNVERIFIED EMAIL ACCOUNTS OLDER THAN 1 WEEK - REQUIRES MANUAL BUTTON PRESS BY ADMIN
{
$verified = 'no';
$tables = array('register', 'profiles', 'profilesmember');
$deletedate = date('Y-m-d', strtotime('-7 days'));
$this->db->select('email');
$this->db->where('is_email_verified', $verified);
$this->db->where("DATE_FORMAT(created_date,'%Y-%m-%d') <='$deletedate'");
$this->db->from('register');
$query = $this->db->get();
foreach($query->result() as $row)
{
$email = $row->email;
$this->db->where('email', $email);
$this->db->delete($tables);
// print_r($email);
}
}