codeigniter join select as

感情迁移 提交于 2019-12-24 00:55:45

问题


I have 2 tables in my database wich i need to join. 1 table is the artikelen table and the other one is the collecties table. I currently have.

  $this->db->select('*');
  $this->db->from('collecties');
  $this->db->join('artikelen', 'artikelen.collecties_id = collecties.id');

It gives the right result but all the double fields (collecties has a title field and artikelen has a title field) will become one (it returns the artikelen.title field), and i cant access the row of the other table (the collecties.title field).

I select 10 fields from artikelen and only collecties.title from collecties.

What is the simples way to do this without having to replace

    $this->db->select('*');

with all the 10 fields with an as statement.


回答1:


Make sure your both table got rows on your joining condition , otherwise it will return null. and modify the select as follows
$this->db->select('artikelen.*,collecties.title as ctitle');



来源:https://stackoverflow.com/questions/22969926/codeigniter-join-select-as

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!