CodeIgniter Forums
update database table with joins - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: update database table with joins (/showthread.php?tid=43624)



update database table with joins - El Forum - 07-18-2011

[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


update database table with joins - El Forum - 07-27-2011

[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 ...


update database table with joins - El Forum - 07-28-2011

[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 !


update database table with joins - El Forum - 07-28-2011

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