0

我想问是否可以在连接后指定 where 子句,以便将数据与用户输入匹配。比如说我有以下代码:

 $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();

我想从表'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();

这可能吗?我可以在 JOIN 之后比较结果(使用 WHERE)吗?这会产生与 WHERE 子句匹配的结果吗?

谢谢!

4

1 回答 1

4

CodeIgniter 直到->get()被调用才真正构建查询。您可以按您想要的任何顺序调用这些方法。

于 2012-12-04T22:47:53.087 回答