Updating email address by adding '@live.com' to the end

I'm trying to update a table of email list by adding '@live.com" at the end, as some users forget to put this suffix for their email address. For example, they input something like "imsuperman" while it should be 'imsuperman@live.com'.

I'm using codeigniter but got stuck at the following code:

        $this->db->select('email, username');
        $user=$this->db->get('user');

        foreach ($user->result() as $row):

        $to_username=$row->username;

        //load email address
        $to_email_raw=$row->email;

        if(strpos($to_email_raw, '@') !==false)
        {
            $to_email=$to_email_raw;
        }
        else
        {
            $to_email=$to_email_raw.'@live.com';
        }

        endforeach;

I've so far changed the email address for each row. Any advice on how I should update the table next?

Thanks,

Answers


If this is existing data in your database you should query the id from the associated row and pass that within your update function.

If you are trying to update a single row in your db use the update function

link

In your controller:

$data = array('id' => $id, 'email' => $to_email);

In your model

function update_email() {     
    $this->db->where('id', $id);
    $this->db->update('mytable', $data);
}

If you are trying to update multiple rows in your db at the same time, use the update batch function

In your controller, within the foreach loop:

$data[] = array('id' => $id, 'email' => $to_email);

In your model

function update_email_batch() {
    $this->db->update_batch('mytable', $data, 'id'); 
}

Need Your Help

"/me/feed?since=" set this 'since' to the updated time in stead of the created time

facebook facebook-graph-api timestamp

I have a application that monitors a businesspage for you, along with other sources like Twitter. For the purpose of internal comments and analytics I store the posts on the wall in our database.