I have this codeigniter function
function allClients($orderby = 'clients_company_name', $sort = 'ASC')
{
//profiling::
$this->debug_methods_trail[] = __function__;
//declare
$conditional_sql = '';
//check if any specifi ordering was passed
if (! $this->db->field_exists($orderby, 'clients')) {
$orderby = 'clients_company_name';
}
//check if sorting type was passed
$sort = ($sort == 'asc' || $sort == 'desc') ? $sort : 'ASC';
//----------sql & benchmarking start----------
$this->benchmark->mark('code_start');
//_____SQL QUERY_______
$query = $this->db->query("SELECT *
FROM clients
ORDER BY $orderby $sort");
$results = $query->result_array(); //multi row array
//benchmark/debug
$this->benchmark->mark('code_end');
$execution_time = $this->benchmark->elapsed_time('code_start', 'code_end');
//debugging data
$this->__debugging(__line__, __function__, $execution_time, __class__, $results);
//----------sql & benchmarking end----------
//return results
return $results;
}
It selects all data from table clients. One of them is "client_team_profile_id" - the owner of this client.
I also need to join other table - team profiles. There we can find team_profile_id (there are ids of users in system) and team_profile_full_name - names of users.
Table: clients
clients_id|clients-company_name|client_address|clients_team_profile_id
1 |Apple |some street |2
2 |Dell |some street |5
Table team_profile
team_profile_id | team_profile_full_name|
2 |John |
5 |Bob |
I need to select all data from table CLIENTS (as we can see - Select *) and also get name of team user connected to client and set a parameter for result - AS f.ex. client_owner_name.
I appreciate your help.