你好我试着加入两张桌子
这是我的简单的SQL查询
$sql="SELECT windows_users_image_upload.*, `windows_users_info`.`display`
FROM `windows_users_image_upload`,`windows_users_info`
WHERE `windows_users_info`.`user_id` = `windows_users_image_upload`.`user_id`
AND ".$field."=".$value;
它的工作正常,但我想将其设置为编码器方式
并尝试这样的事情。
$this->db->select("windows_users_image_upload.*,windows_users_info.display");
$this->db->from("windows_users_info,windows_users_image_upload");
$this->db->where("windows_users_image_upload.".$field,$value);
$this->db->limit($takeTuple, $startTuple);
$this->db->join("windows_users_image_upload,windows_users_image_upload.user_id = windows_users_info.user_id");
$result = $this->db->get()->result();
但它显示我的错误
消息:CI_DB_active_record缺少参数2 :: join()
我该如何解决这个问题 感谢。
答案 0 :(得分:1)
这是您在CodeIgniter中使用联接的方式:
$this->db->select('*');
$this->db->from('blogs');
$this->db->join('comments', 'comments.id = blogs.id');
$query = $this->db->get();
// Produces:
// SELECT * FROM blogs
// JOIN comments ON comments.id = blogs.id1
您可以在CodeIgniter的用户指南中看到它。
http://ellislab.com/codeigniter/user-guide/database/active_record.html#select
答案 1 :(得分:1)
您必须从命令中删除第二个表:
示例:
$this->db->select('windows_users_image_upload.*,windows_users_info.display');
$this->db->from('windows_users_info');
$this->db->join("windows_users_image_upload","windows_users_image_upload.user_id = windows_users_info.user_id");
$this->db->where("windows_users_image_upload.".$field,$value);
$query = $this->db->get();