a7omiton
a7omiton

Reputation: 1617

Specifying a WHERE clause after a JOIN clause - Active Record - CodeIgniter

I wanted to ask is it possible to specify a where clause after a join in order to match data to a users input. Say for example I have the following code:

 $this->db->select('user.*,role.*')
  $this->db->from('user');
  $this->db->where('user.username', $username);
  $this->db->where('user.password', $password);
  $this->db->join('role','role.id = user.role_id')
  $result = $this->db->get();

and I want to query the matching data from the table 'role':

 $this->db->select('user.*,role.*')
  $this->db->from('user');
  $this->db->where('user.username', $username);
  $this->db->where('user.password', $password);
  $this->db->join('role','role.id = user.role_id')
  $this->db->where('role.speaker', $speaker); //want to know if this is correct
  $result = $this->db->get();

Is this possible? Can I compare results (using WHERE) after a JOIN? Will that produce results matching to the WHERE clause?

Thanks!

Upvotes: 0

Views: 4812

Answers (1)

gen_Eric
gen_Eric

Reputation: 227240

CodeIgniter doesn't actually build the query until ->get() is called. You can call the methods in whatever order you want.

Upvotes: 4

Related Questions