我正在使用CodeIgniter PHP框架和MySQL作为数据库。我要显示房间的特定平面图(img),也要显示没有房间的建筑物。
我有3张桌子:
tblbldg-建筑
小房间-房间
tblfloorplan-楼层平面图
我尝试了这段代码,但最终却混入了img,就像building1 floor1与2号楼floor1显示相同的平面图:
public function get_rooms(){ $this->db->select('tblroom.id, tblroom.name, tblroom.floor, tblbldg.name as building_name, tblfloorplan.img'); $this->db->from('tblroom'); $this->db->join('tblbldg',"tblbldg.id = tblroom.building_id"); $this->db->join('tblfloorplan',"tblfloorplan.floor = tblroom.floor"); return $this->db->get(); }
答案 0 :(得分:0)
尝试一下
public function get_rooms(){
$this->db->select('tblroom.id,
tblroom.name,
tblroom.floor,
tblbldg.name as building_name,
tblfloorplan.img');
$this->db->from('tblroom');
$this->db->join('tblbldg',"tblbldg.id = tblroom.building_id");
$this->db->join('tblfloorplan',"tblbldg.id = tblfloorplan.building_id and tblfloorplan.floor = tblroom.floor");
return $this->db->get();
}