首页 > 解决方案 > Codeigniter Join 如果值不为 NULL

问题描述

我想要代码,如果我找到了字段数据,那么我想将该特定数据加入另一个表。

    $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();

如果我得到 userprofile.bodyType 然后 bodytype joinquery 运行。有什么办法来处理它?

标签: javascriptphpcodeigniterjoin

解决方案


尝试 INNER JOIN :

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

推荐阅读