我使用codeigniter并存储 123,234 之类的数据。
我的表名是schedule
,列名是batch
。
$batch = 123;
$lot =1;
$dataTest = $this->db->query("select q_set from schedule where lot='$lot'
and batch='$batch'")->row();
在下面查看我的图片
我尝试选择一个值并匹配我发送的值。 ##如何同时匹配两个值##
答案 0 :(得分:2)
数据库中列批处理的值为'123,321',变量$ batch为123,它们不相等,因此无法选择它。 您必须发送与数据库中相同的数据。
尝试
$lot=1;
$batch = 123321; //or $batch='123,321' i'm not sure the date type of variable $batch
$dataTest = $this->db->query("select q_set from schedule where lot='$lot' and batch='$batch'")->row();
答案 1 :(得分:2)
尝试一下
$batch = "123,321";
$lot =1;
$dataTest = $this->db->query("select q_set from schedule where lot=".$lot."
and batch='".$batch."')->row();
或使用
$batch = "123";
$lot =1;
$dataTest = $this->db->query("select q_set from schedule where lot=".$lot."
and batch like '%".$batch."')->row();
答案 2 :(得分:2)
使用查询生成器。请注意,如果batch是字符串,则应为$batch = "123,234"
,而且您不能使用整数逗号。
$this->db->select('q_set');
$this->db->where('lot', $lot);
$this->db->where('batch', $batch);
$q = $this->db->get('schedule');
if ($q->num_rows() > 0}
print_r($q->row());
} else {
echo 'no rows';
}
答案 3 :(得分:0)
您也可以使用find_in_set。但是它通常用于查找逗号分隔的值。
$this->db->select('q_set');
$this->db->from("schedule");
$this->db->where("FIND_IN_SET('$lot', lot)");
$this->db->where("FIND_IN_SET('$batch', batch)");
--------------或---------------
您可以尝试一下。
$this->db->select('q_set');
$this->db->from('schedule as S1');
$this->db->where('S1.lot',$lot);
$this->db->where('S1.batch',$batch);
$query = $this->db->get();
return $query->row();
答案 4 :(得分:0)
您可以使用IN运算符,
$result = $this->db->select('*')->from($table);
$result = $this->db->where('lot =',$lot);
$result = $this->db->where_in('batch',$batch);
$result = $this->db->order_by('id','desc');
$result = $this->db->get();
where_in()运算符检查指定列中是否存在该值