Skip to content
Advertisement

Codeigniter: Joining multiple tables

I have 3 tables with the following columns

JavaScript

I joined them by

JavaScript

Question:

Since all columns are selected, is it possible to select a column from a definite table(such as item_brand.name)?

I did the following code, yet I am getting zero results. but if I remove this following line,

JavaScript

and loading $data['name'] to the view, all I get is the brand.name

I need to join the 3 tables. But I failed to do so.

Edit: I managed to make a solution for the columns, however, I’m getting zero results joining the 3 tables.

JavaScript

Advertisement

Answer

Is it possible to select a column from a definite table(such as item_brand.name)?

Yes, you can select column from definite table using select as below :

JavaScript

And if you are not getting results while joining your item_category table i.e.

JavaScript

then there must be issue with the foreign key i.e. join uses inner join of mysql which takes all intersect(common) data between the joined tables and there must be no matching id(foreign key) in item_category and items table. So, you can use rightjoin to get the data. Which will take all data from items table and all the data from item_category table if there is any matching foreign key (items_category.id) from items table. So, what you can do is :

JavaScript

If you want to explore more then you can visit this doc .

Hope it helps. Happy coding 🙂 .

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement