mysql join problem |
08-17-2021, 06:28 AM
(This post was last modified: 08-18-2021, 12:51 AM by InsiteFX. Edit Reason: Fixed code tags please use them )
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
@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'); (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.
Try this.
PHP Code: $builder = $this->db->table('elongate'); Also you can use $db->getLastQuery(); to see what your query looks like. What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
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 |
Welcome Guest, Not a member yet? Register Sign In |