Multiple Joins in Codeigniter

前端 未结 4 1950
孤独总比滥情好
孤独总比滥情好 2020-12-08 23:33

I\'m new to building databases and I\'m trying to do a JOIN based on a having three database tables.

Table A = ID, Name, etc
Table B = ID, Name, etc
Table C          


        
4条回答
  •  鱼传尺愫
    2020-12-09 00:14

    $this->db->select('*');
    
    $this->db->from('table1');
    
    $this->db->join('table2','table1.id=table2.id'); 
    
    $this->db->join('table3','table2.id=table3.id');
    
    $this->db->join('table4','table3.id=table4.id'); 
    
    $this->db->join('table5','table5.id=table4.id');
    
    $this->db->where('table5.id',$this->session->userdata('id'));//getting value from session and match the id of table5 and then show data
    
    $data=$this->db->get()->result();//all data store in $data variable
    

提交回复
热议问题