简体   繁体   中英

Get data form multi table in Codeigniter using SQL Join

Receiving error like Not unique table/alias: 'provinces' , below function is of model function , I create this function in model but getting error table/alias

function get_data_three_tbl(){

                $this->db->select('blood_donors.id, blood_donors.full_name, blood_donors.area, blood_donors.email, blood_donors.phone, provinces.province_name,districts.district_name, tehsils.tehsil_name, blood_groups.group_name');
                $this->db->from ( 'blood_donors, provinces, districts, tehsils, blood_groups ' );
                $this->db->where('blood_donors.is_deleted',1);
                $this->db->join('provinces','provinces.province_id = blood_donors.province');
                $this->db->join('districts','districts.district_id = blood_donors.district');
                $this->db->join('tehsils','tehsils.tehsil_id = blood_donors.tehsil');
                $this->db->join('blood_groups','blood_groups.id = blood_donors.blood_goup');
                $query = $this->db->get();
                if ($query->num_rows() > 0)
                return $query->result_array();
                else
                return FALSE;
    }

Change the from() call to

$this->db->from('blood_donors');

The join statements take care of the other tables. Having the table names in both the from and join statements is the reason for the not unique error.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM