mysql join problem - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24) +--- Thread: mysql join problem (/showthread.php?tid=79927) |
mysql join problem - magiwells - 08-17-2021 My join is inserting the foreign key in place of the primary key. PHP Code: $builder = $this->db->table('elongate'); But the [id] should be 1,2,3,4 respectively RE: mysql join problem - php_rocs - 08-17-2021 @magiwells , Maybe in your join statement you should specify which join you wish to use... Options are: left, right, outer, inner, left outer, and right outer. Your statement: $builder->join('city', 'city.id = elongate.city_id'); Try (one of the options listed above. I chose left for this example): $builder->join('city', 'city.id = elongate.city_id', 'left'); RE: mysql join problem - magiwells - 08-17-2021 (08-17-2021, 07:26 AM)php_rocs Wrote: @magiwells , I tried the join options before I posted and got the same result. It's weird when I do a sql query outside of Codeigniter, I get the expected result. There must be something Im overlooking. I am just learning Codeigniter. RE: mysql join problem - InsiteFX - 08-18-2021 Try this. PHP Code: $builder = $this->db->table('elongate'); Also you can use $db->getLastQuery(); to see what your query looks like. RE: mysql join problem - iRedds - 08-18-2021 try to remove city.id from the select section. you already got the city.id as elongated.city_id in your case elongate.id will be replaced with city.id RE: mysql join problem - magiwells - 08-18-2021 (08-18-2021, 03:05 AM)iRedds Wrote: try to remove city.id from the select section. This was it Thank you RE: mysql join problem - php_rocs - 08-18-2021 @magiwells , Also, if you still want city.id as a part of your results you could do this... $builder->select('elongate.id, elongate.catalog_num, elongate.city_id, elongate.venue_id, city.id as city_id, city.city_name'); Then city.id would be called city_id instead of id. |