我想像这样的SQL查询
SELECT * FROM `tblName`
where `id`='007' and
`doj` != '2014-07-26' and
`doj` != '2014-08-04'
我想在where子句中使用相同的列'doj'。
请帮帮我?
提前致谢。
答案 0 :(得分:0)
<?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();
?>