我正在使用代码点火器实现连接查询。我有两张桌子
1) Users -> Contains all users
2) Query -> Contains queries assigned to users. Each query has two users to attend that query.
在Queries表中我有两列
1) attendingMD -> First user attending that query
2) secondAttendingMD -> Second user that query.
我想显示查询列表以及参与该查询的两个用户的名称。我设法通过使用此代码获得第一个用户的名称。
$this->db->select("Query.*, Users.fullname as firstMD");
$this->db->join('Users', 'Users.id = Query.attendingMD');
$this->db->where('Query.isCompleted', 1);
$query = $this->db->get('Query');
return $query->result_array();
答案 0 :(得分:5)
尝试:
$this->db->select("Query.*, uf.fullname as firstMD, us.fullname as secondMD");
$this->db->join('Users uf', 'uf.id = Query.attendingMD');
$this->db->join('Users us', 'us.id = Query.secondAttendingMD');
$this->db->where('Query.isCompleted', 1);
$query = $this->db->get('Query');
return $query->result_array();