Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/60.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在Codeigniter中连接3个表没有结果_Php_Mysql_Codeigniter - Fatal编程技术网

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