Welcome Guest, Not a member yet? Register   Sign In
Querying 2 tables in 1 functon
#7

[eluser]CroNiX[/eluser]
You would use a join. I'll show the concept and you can go from there...You can fine tune with db::where(), and an additional join on your agent table, grab additional fields, etc

Users
-id
-role_id
-email
-name

Roles
-id
-name

Code:
//get all user names and email from user table, and their role_name from roles table
//since users and roles table both have a "name" column, alias the role.name as role_name to avoid collision
$users = $this->db
  ->select('users.email, users.name, roles.name as role_name')
  ->join('roles', 'roles.id = users.role_id', 'left') //get the role where the role.id = the users.role_id
  ->get('users')
  ->result();


Messages In This Thread
Querying 2 tables in 1 functon - by El Forum - 01-17-2014, 03:05 PM
Querying 2 tables in 1 functon - by El Forum - 01-17-2014, 06:30 PM
Querying 2 tables in 1 functon - by El Forum - 01-18-2014, 03:01 AM
Querying 2 tables in 1 functon - by El Forum - 01-18-2014, 04:22 AM
Querying 2 tables in 1 functon - by El Forum - 01-18-2014, 04:35 AM
Querying 2 tables in 1 functon - by El Forum - 01-18-2014, 05:30 AM
Querying 2 tables in 1 functon - by El Forum - 01-18-2014, 11:28 AM
Querying 2 tables in 1 functon - by El Forum - 01-18-2014, 02:15 PM



Theme © iAndrew 2016 - Forum software by © MyBB