codeigniter加入选择为 [英] codeigniter join select as
问题描述
我的数据库中有2个表,需要我加入。
1个表是artikelen表,另一个是collecties表。我当前有。
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');
它给出正确的结果,但所有双精度字段(collection有title字段,artikelen具有title字段)将变成一个(它返回artikelen.title字段),而我无法访问其他表的行(collecties.title字段)。
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).
我从artikelen中选择了10个字段,而从collecties中只选择了collecties.title。
I select 10 fields from artikelen and only collecties.title from collecties.
简单的方法是无需替换
$this->db->select('*');
所有10个字段均带有as语句。
with all the 10 fields with an as statement.
推荐答案
确保两个表都具有连接条件所对应的行,否则它将返回null。并按如下所示修改选择
$ this-> db-> select('artikelen。*,collecties.title as ctitle');
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');
这篇关于codeigniter加入选择为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!