Saturday, 15 February 2014

php - codeigniter join many to many LIMIT -


I have three tables:

  Products: Model_ID, model (unique), group : Group_ID, code (unique), products_group: pg_id, model_id_fk, group_id_fk   

product-group group table 'many-to-many' relationships between 'products' and 'groups' Is for

Include my left:

  $ this-> Db- & gt; Select ('Model_ID, Model, Code'); $ This- & gt; Db- & gt; ('Product'); $ This- & gt; Db- & gt; Join ('products_group', 'products_group.model_id_fk = products.model_id', 'left'); $ This- & gt; Db- & gt; Join ('groups', 'groups.group_id = products_groups.group_id_fk', 'left'); $ Query = $ this- & gt; Db- & gt; Receive () - & gt; Result_are ();   

Result:

  | ------------------------- | | Model_ID | Model | Code | | ------------------------- | | 0 | 1000 | 15 | | 0 | 1000 | 20 | | 0 | 1000 | 30 | | 1 | 2000. 15 | | 1 | 2000. 20 | | ------------------------- |   

What do I need:

  | ------------------------ ------- | | Model_ID | Model | Code | | ------------------------------- | | 0 | 1000 | 15,20,30 | 1 | 2000. 15,20. | ------------------------------- |   

Solution (?): The first thing that comes to mind is to 'sequence by products.model_id' and then go through the result row by row, mix those rows with Include the 'Model_ID' and their 'code' values.

PROBLEM: I want to score points on the page and if I make a limit on the query, then the number of rows together with the rows will be disturbed. >

So I'd suggest, how do I do this?

PS This is only part of the information, there is another 'many-to-many' relationships with another table in the 'product' table, which is one-to-many relations with one-third Are there. One more 'many-to-many' relationships may be added.

by model_id and group_concat code by group

No comments:

Post a Comment