Many of the many join the request at CodeIgniter

All previous JOIN attempts left me disk or element data filling in the identifier, the result header keys (possibly a collision occurs).

So, I have a:

item table
fields: id, title

disc table
fields: id, title

item_disc table
fields: item_id, disc_id

How to create a double connection so that I can access the associated disks with the item. I am currently running two separate queries: one for writing one item, then one for an array of disks.

In addition, which is easier to do in a single query with joins, if I ever want to get more than one record, currently I will need to run 2 queries for each element, since I cannot join my data.

Please, help!! I feel that this is my last many, many obstacles (although I dare not speak too soon).

+3
2

id title, . as, ...

:

select m.*, i.title as item_title, d.title as disc_title
from item i, disc d, item_disc m where i.id = m.item_id and
d.id = m.disc_id order by i.title, d.title

:

select m.*, i.title as item_title, d.title as disc_title
from item i, disc d, item_disc m where i.id = m.item_id = ? and
d.id = m.disc_id order by d.title

? ,

+4

Source: https://habr.com/ru/post/1729836/


All Articles