【问题标题】:Same column name used in where clause in codeigniter在 codeigniter 的 where 子句中使用相同的列名
【发布时间】:2014-08-04 11:20:06
【问题描述】:

我想要这样的 sql 查询

SELECT * FROM `tblName`
where `id`='007' and 
`doj` != '2014-07-26' and 
`doj` != '2014-08-04'

我希望在 where 子句中使用同一列“doj”。

请帮帮我?

提前致谢。

【问题讨论】:

    标签: sql arrays codeigniter


    【解决方案1】:
    <?php 
    $dates = array(
         '2014-07-26',
         '2014-08-04'
    );
    $this->db->from('tblName');
    $this->db->where('id','007');
    
    // first variant
    foreach($dates as $date){
    $this->db->where('doj !=',$date);
    }
    
    // or second variant
    $this->db->where_not_in('doj',$dates); // <- seems to be better
    
    // finally get result
    $result = $this->db->get();
    
    if($result->num_rows()){
         var_dump($result->result_array());
    } else {
         echo 'no rows found';
    }
    // check query
    echo $this->db->last_query();
    
    ?>
    

    【讨论】:

    • 感谢@George,但我希望动态查询或借助模型查询,因为doj 会在一段时间后增加。
    • @VaibhavSinghal 更新了我的答案,请检查一下。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-04-11
    • 2013-06-27
    • 1970-01-01
    • 2011-03-15
    • 1970-01-01
    • 2020-09-14
    • 1970-01-01
    相关资源
    最近更新 更多