• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Join Problems

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

function get_all($user_id)
    $query = $this
                ->join('ratings', 'ratings.user_id = users.id')
                ->join('favs', 'favs.user_id = users.id')
                ->where('users.id', $user_id)
    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.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.