php - Codeigniter Joining 4 Tables -


I am stuck in creating SQL statements to join tables.

Actually I have 4 tables and 2 table with foreign key is linked to table sequence product table and field table. And the distribution table is linked to the sequence table.

Table product

id | Product_desc

Table Area

ID | Region_desc

Table Sequence.

ID | Product_id | Region_id

table distribution

ID | Sequence_id | Sales | Distribution_fee

My model code:

  $ this-> Db- & gt; Choose ('*'); $ This- & gt; Db- & gt; ('Distribution'); $ This- & gt; Db- & gt; Join ('sequence', 'sequence.id = distribution; result,' 'left'); $ This- & gt; Db- & gt; Join ('sequence', 'sequence.product_id = product.product_no'); // error $$ ----- gt; DB- & gt; Join ('sequence', 'sequence.region_id = regions.edit'); // error $ $ ---> db-> By order ('distributions.id', 'asc'); $ Query = $ this- & gt; Db- & gt; get receive (); If ($ query-> num_rows ()! = 0) {Return to $ query- & gt; Result_are (); } Other {return false; }  

Any solutions? It will be highly appreciated.

Thank you in advance

You fields and Products are not referring tables

Try something like this:

  $ this-> Db- & gt; Choose ('*'); $ This- & gt; Db- & gt; ('Distribution'); $ This- & gt; Db- & gt; Join ('sequence', 'sequence.id = distribution; result,' 'left'); $ This- & gt; Db- & gt; Join ('product', 'sequence.product_ID = product.product_no'); $ This- & gt; Db- & gt; Join ('regions', 'sequence.region_id = regions.id'); $ This- & gt; Db- & gt; Order_by ('distributions.id', 'asc'); $ Query = $ this- & gt; Db- & gt; get receive (); If ($ query-> num_rows ()! = 0) {Return to $ query- & gt; Result_are (); } Other {return false; }  

Comments