简体   繁体   English

Codeigniter Join 如果值不为 NULL

[英]Codeigniter Join If the value is not NULL

I want the code that I if I found the field data then I want to join that particular data to another table.我想要代码,如果我找到了字段数据,那么我想将该特定数据加入另一个表。

    $this->db->select('*');
    $this->db->from('userprofile');
    $this->db->where('userId', $userId);
    $this->db->where('status', 1);
    $this->db->join('bodytype', 'bodytype.bodyTypeId = userprofile.bodyType');
    $this->db->join('children', 'children.childrenId = userprofile.children');
    $this->db->join('ethnticity', 'ethnticity.ethnticityId = userprofile.ethnicity');
    $this->db->join('smoke', 'smoke.smokeId = userprofile.smoke');
    $this->db->join('drink', 'drink.drinkId = userprofile.drink');
    $query = $this->db->get();
    return $query->result();

If I got the userprofile.bodyType then and then the bodytype joinquery run.Is there any way to handle it?如果我得到了 userprofile.bodyType 然后 bodytype joinquery 运行。有没有办法处理它?

from this stack: Value IS NOT NULL in codeigniter来自此堆栈: codeigniter 中的值不为空

add this where clause to query添加此 where 子句进行查询

$this->db->where('bodyType is NOT NULL', NULL, FALSE);

尝试内部连接:

$this->db->join('bodytype', 'bodytype.bodyTypeId = userprofile.bodyType','inner');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM