CodeIgniter Forums

Full Version: join not returning all rows
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

i have 3 tables involved in this query. The first is an entry table which can have 1 or more users associated with it by the entry_user table. Then I have the user table which holds the user info. The following sql command works.

select, user.first_name
from entry
left join entry_user on = entry_user.entry_id
left join user on entry_user.user_id =
where = 9;

in this example the entry table is associated with 2 users. so it returns:

| id | first_name |
| 9 | David |
| 9 | Jonny |

But when I try and use the codeigniter object oriented method it only returns 1 row, ie 1 name. here is the code i tried:

$this->db->select(' AS entry_id, user.first_name AS first_name');
$this->db->join('entry_user', ' =', 'left');
$this->db->join('user', 'entry_user.user_id =', 'left');
$this->db->where(' = 9');
$query = $this->db->get();

I know that I can put the straight sql command in the get command but I want to use the object oriented method if possible for clean code. can anybody tell me what I am doing wrong? thanks.

El Forum

Could you display the query-string rendered by your code?

El Forum

In your join to entry_user, your original sql references entry_user.entry_id but your AR version references

El Forum

thanks bigtony - that did the trick. sometimes after looking at code all night, you miss the simplest things.