Php 在Codeigniter中连接3个表没有结果
即使数据库中有数据,也没有结果:Php 在Codeigniter中连接3个表没有结果,php,mysql,codeigniter,Php,Mysql,Codeigniter,即使数据库中有数据,也没有结果: $this->db->select('*'); $this->db->from('user'); $this->db->join('userprofile', 'user.userID = userprofile.userID'); $this->db->join('classroom', 'user.classroomID = classroom.classroomID'); $this->db->
$this->db->select('*');
$this->db->from('user');
$this->db->join('userprofile', 'user.userID = userprofile.userID');
$this->db->join('classroom', 'user.classroomID = classroom.classroomID');
$this->db->where('roleID',"4");
$query = $this->db->get();
return $query->result();
在连接时,必须使用where条件定义表名。如下所示
$this->db->select('*');
$this->db->from('user');
$this->db->join('userprofile', 'user.userID = userprofile.userID');
$this->db->join('classroom', 'user.classroomID = classroom.classroomID');
$this->db->where('table_name.roleID',4);//table_name is name of table having column roleID
$query = $this->db->get();
return $query->result();
是否可以共享需要快照的表数据。。。。。
$this->db->select('*');
$this->db->from('user');
$this->db->join('userprofile', 'user.userID = userprofile.userID');
$this->db->join('classroom', 'user.classroomID = classroom.classroomID');
$this->db->where('roleID',"4");
$query = $this->db->get();
return $query->result();
your query work with one table data when you join another table you can must define $this->db->where('user.roleID',4) like this.
you can write this query like this for when you get the join table data
$this->db->select('user.*,userprofile.youdesirename,classroom.class name');
$this->db->from('user');
$this->db->join('userprofile', 'user.userID = userprofile.userID');
$this->db->join('classroom', 'user.classroomID = classroom.classroomID');
$this->db->where('user.roleID',4)
$query = $this->db->get();
return $query->result();