Welcome Guest, Not a member yet? Register   Sign In
Join statements going wrong.
#2

[eluser]Mirage[/eluser]
At first glance, I'd suggest to alias the first join as well:

Code:
$this->db->select('posts.*, user1.username as poster, user1.useremail as posteremail, user2.username as updater, user2.useremail as updateremail');
$this->db->order_by("posts.id", "desc");
$this->db->join('user as user1', 'user1.id = posts.postedBy');
$this->db->join('user as user2', 'user2.id = posts.updatedBy');

Also I'd suggest you debug $this->db->last_query() to see what query was generated.

Finally - are you sure that the updatedBy field contains a valid id when the posted is new. It'd say it should be the same as the postedBy but if you want to discern the update status as 'never updated' then perhaps make it default to 0 or null and use 'left' on the user2 join.

Do let us know how it goes...

Cheers,
-m


Messages In This Thread
Join statements going wrong. - by El Forum - 09-13-2008, 06:09 AM
Join statements going wrong. - by El Forum - 09-13-2008, 01:00 PM
Join statements going wrong. - by El Forum - 09-13-2008, 01:41 PM
Join statements going wrong. - by El Forum - 09-13-2008, 01:49 PM
Join statements going wrong. - by El Forum - 09-13-2008, 01:58 PM



Theme © iAndrew 2016 - Forum software by © MyBB