Reputation: 1559
I am trying to figure out why my JOIN is not working on a database query, I have two tables with a user_ID column, but when I return this it returns everything, not just the selected ones per user. What am I messing up any thoughts? Thank you!
function user_apps()
{
$this->db->select('*');
$this->db->from('apps');
$this->db->join('members', 'members.user_ID = apps.user_ID');
$query = $this->db->get();
return $query;
}
Here is an image of the DB tables, and goal is to basically get the urls from the apps table of each user, http://cl.ly/516bd1e8aae62bd11773
Upvotes: 0
Views: 239
Reputation: 3692
You haven't specified a WHERE clause in your query. At the moment it is returning everything because you only have two users and they both have entries in the 'apps' table. If you add:
$this->db->where('members.first_name', $first_name);
And pass a first name as a parameter to the function then it will only return results for that user.
function user_apps($first_name)
{
$this->db->select('*');
$this->db->from('apps');
$this->db->join('members', 'members.user_ID = apps.user_ID');
$this->db->where('members.first_name', $first_name);
$query = $this->db->get();
return $query;
}
Upvotes: 1