getting data from 2 different table with JOIN sql. Codeigniter -
I use codeigniter, and I need to get data from 2 different tables for now only this works_image table How do I get data from both tables?
Thanks a lot! Select
$ this-> db-> ('works_image. *', 'Works. *'); From $ the-> db-> ('works_image', 'works'); $ The-> db-> Join ('works', 'works.id = works_image.id_work'); $ Result = $ this-> db-> get (); Foreign exchange ($ result-> result () as $ line) {echo "#". $ Line-> ID "-" $ line-> thumb "-" $ line-> wname "
"; }
Unless you are SELECT *
(), you < There should be no need to specify the tables with the call at select code> () . This will select all the fields by default.
$ this-> Db- & gt; ('Works_image', 'works'); $ This- & gt; Db- & gt; Join ('works', 'works.id = works_image.id_work'); $ Result = $ this- & gt; Db- & gt; get receive ();
Should work fine.
Instead, what you are actually doing tells you exactly which field you need:
$ it-> DB- & gt; Select ('works_image.id, works_image.name, works_image.id_work, works.id, works.name'); // (or whatever area you are interested in) $ this- & gt; Db- & gt; ('Works_image', 'works'); $ This- & gt; Db- & gt; Join ('works', 'works.id = works_image.id_work'); $ Result = $ this- & gt; Db- & gt; get receive (); In this way, you can ensure that (a) you are not pulling unnecessary data from your DB, and (b) if your DB schema.
Comments
Post a Comment