CodeIgniter Forums
Join Problems - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Join Problems (/thread-43392.html)



Join Problems - El Forum - 07-09-2011

[eluser]Unknown[/eluser]
I am trying to join a few tables together and am not sure I am doing it properly...what i want to accomplish is being able to combine all the different actions a user is capable of and put them into an activity feed sorta list...right now it is just favs and ratings but in the future it could be more... Here is the code i have in my model


Code:
function get_all($user_id)
{
    $query = $this
                ->db
                ->select('*')
                ->from('users')
                ->join('ratings', 'ratings.user_id = users.id')
                ->join('favs', 'favs.user_id = users.id')
                ->where('users.id', $user_id)
                ->get();
    
    if($query->num_rows() > 0) return $query->result();
    return false;
}

favs and ratings are 2 tables which have the columns (id, user_id, shop_id)...ratings also has column 'rating' and fav has column 'list_id' where rating does not.

the code does run but gives results back the wrong way. if i comment out either of one of the join lines i get correct results.
being 4 rows / entries for 'ratings' (for the user i am testing) and 2 rows / entries for 'favs' (for the user i am testing)

but currently it's returning 8 rows...but they are the same 2 rows of the 'favs' over and over again.

any help would be greatly appreciated.

thanks,
b