Reputation: 553
I have a function to get a single user from the database so I can show it, for user profiles and stuff.
Well I want to be able to have a seperate table just for groups, so I can add more if I want to and it be simple. So I have a group_id field in the users table so I can do that, and it would join the groups table with the groups id column.
Well I was able to do it successfully for another project of mine, but when I moved the function over to this current project (I'm using the same EXACT methods to display the profile on both projects) it no longer works... keeps returning nothing at all...
public function getUser($username) {
if (empty($username)) {
return false;
}
$this->ci->db->from('users');
$this->ci->db->join('groups','users.group_id = groups.id');
$query = $this->ci->db->where('username',$username)->get();
$user = $query->row();
return $user;
}
That is the function, could someone please help me as to why it's not working? I have tried it in the controller, the model, and the library, and none of them are working.
Upvotes: 0
Views: 192
Reputation: 553
I feel stupid, but anyway I found the issue.
I forgot to actually add a value into the column for that specific user for the group_id
So the group_id in the column was 0, when it needed to be at least 1 or higher, after changing it, it worked just fine...
Thanks for all of your help tho, both of you.
Upvotes: 2