【问题标题】:I want to access record of null in where condition我想在 where 条件下访问 null 的记录
【发布时间】:2019-08-03 06:57:44
【问题描述】:

在我的crossing_cash_memo 表中的due_to 列中,值为consigneecash,其他为空。我想隐藏cash 数据并显示剩余数据,但我的空数据未显示。

我正在尝试这样:

  public function fetchDue($rec_type){
  $query = $this->db->select('user.user_full_name as consignor,user1.user_full_name as consignee,c.*')
         ->from('crossing_cash_memo c')

         ->join('ts_users user', 'c.consignor_name=user.user_id')
         ->join('ts_users user1', 'c.consignee_name=user1.user_id')

         ->where('c.memo_status','cash_memo')
         ->where_not_in('c.due_to','cash') 
         ->order_by('c.lr_no','asc')
         ->get();                            
         return $query->result();
  }

如何在 where 条件下显示 NULL 记录

【问题讨论】:

  • 试试->where_not_in('c.due_to',['cash'])
  • 试试 where('c.due_to' !=,'cash');
  • @Jack 仍然没有显示我的null 记录它只隐藏cash 记录我想显示所有剩余的记录。
  • @DevsiOdedra as per image 4,7 is NULL 我也想显示空记录。
  • @farhantechno ->where_not_in('c.due_to',['cash']) 将仅排除 cash 并显示所有其他记录。 null 没有得到因为加入可能是,显示你的整个table 结构

标签: php mysql sql codeigniter


【解决方案1】:

试试这个

    public function fetchDue($rec_type){
       $query = $this->db->select('user.user_full_name as consignor,user1.user_full_name as consignee,c.*')
     ->from('crossing_cash_memo c')

     ->join('ts_users user', 'c.consignor_name=user.user_id', 'left')
     ->join('ts_users user1', 'c.consignee_name=user1.user_id', 'left')

     ->where(array('c.memo_status' => 'cash_memo', 'c.due_to !=' =>'cash'))
     ->order_by('c.lr_no','asc')
     ->get();                            
     return $query->result();
  }

【讨论】:

    【解决方案2】:

    试试这个方法,我没有正确的表名你把它改成你的

     $query =$this->db->query("SELECT * from crossing_cash_memo Left outer join ts_users on `ts_users`.`user_id` = `crossing_cash_memo`.`consignor_name` left outer join ts_users on `ts_users`.`user_id`= crossing_cash_memo.consignee_name where memo_status = 'cash_memo' and where due_to != 'cash' order by lr_no ASC")->result_array();
     }
    

    【讨论】:

    • 在函数中你提到了 $rec_type 这个你在查询中使用的地方?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-10-21
    • 2018-11-21
    • 1970-01-01
    • 1970-01-01
    • 2020-01-31
    • 2018-11-20
    • 1970-01-01
    相关资源
    最近更新 更多