CodeIgniter Forums

Full Version: update database table with joins
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]jerry01[/eluser]
In case this is useful to someone (because i could not find any example out there)

i need to update a table with a where clause on a joined table


Code:
function update_status ($username,$id, $status)
{
      $this->db->join('tbl_updated', 'tbl_joined.id = tbl_updated.join_id');
        $this->db->from('tbl_updated', 'tbl_joined');
        $this->db->where('tbl_updated.id', $id);
        $this->db->having('tbl_joined.username', $username);
    return $this->db->update('tbl_updated', array('status' => $status));
}

anyway, somehow this works

any comments or question i'll try and help

El Forum

[eluser]BaRzO[/eluser]
Hi Jerry,
Thnks for your post.
How can I update users.user_name and groups.group_name ?
And can you pls give an example for sub queries with joins ...

El Forum

[eluser]jerry01[/eluser]
sorry buddy, i don't have any example for that...

a bit busy at the mo toinvestigate

good luck though

ps: your english seems fine to me !

El Forum

[eluser]BaRzO[/eluser]
Thank for your time Smile