【发布时间】:2012-01-19 18:37:14
【问题描述】:
我有两个用于存储用户信息的表。一种是用于身份验证,另一种是用户将自己输入的信息。我正在编写一个模型,当用户与此信息交互时将使用该模型。下面的方法是返回数据进行显示和修改。
我需要一个查询,它将从 $accounts_table 返回“电子邮件”和“用户名”,从 $profiles_table 返回 *。不过,我似乎无法理解 JOIN 语法。我了解连接的工作原理,但我的查询会引发语法错误。
function get_userdata($id){
$data = array();
$this->db->get_where($this->profiles_table, array('user_id' => $id));
$this->db->join($this->accounts_table.'.email', $this->accounts_table.'.id = '.$this->profiles_table.'.user_id');
$data= $this->db->get();
return $data;
}
【问题讨论】:
-
你能发布错误信息吗?
-
我终于让查询完成了它应该做的事情,但我不得不直接使用 mySQL:
function get($id) { $record=$this->db->query(' SELECT '.$this->profiles_table.'.*, '.$this->accounts_table.'.username, '.$this->accounts_table.'.email FROM '.$this->profiles_table.' LEFT JOIN '.$this->accounts_table.' ON '.$this->profiles_table.'.user_id = '.$this->accounts_table.'.id WHERE '.$this->profiles_table.'.user_id = '.$id); return $record->row_array(); }这将如何在 CI 表示法中链接起来......为了胜利?
标签: mysql codeigniter