我有这样的疑问。
WHERE (timetable_id = '1'
OR timetable_id = '2'
OR timetable_id = '3'
OR timetable_id = '4'
OR timetable_id = '5'
OR timetable_id = '6')
AND exam_name_id = '5'但我不知道如何在Codeigniter中执行此操作。
我试过这个
while(@$i <= 6 {
$this->db->or_where('timetable_id',$this->input->post('timetable_id'.$i));
$i++;
}
$this->db->where('et.exam_name_id',5); 但是上面的命令提供这样的输出
WHERE timetable_id = '1'
OR timetable_id = '2'
OR timetable_id = '3'
OR timetable_id = '4'
OR timetable_id = '5'
OR timetable_id = '6'
AND et.exam_name_id = '5'这就提供了所有的输出。如何正确地做到这一点?请注意,在我的查询中我有()大括号。
发布于 2015-04-06 09:38:40
@$i = 1;
$n = $this->input->post('timetable_id'.$i);
$or_where = "(";
$or_where.="timetable_id = $n";
for ($i; $i <= 6; $i++) {
$n = $this->input->post('timetable_id'.$i);
$or_where.=" OR timetable_id = $n";
}
$or_where.=")";
$this->db->or_where($or_where);这将给你预期的答案。
发布于 2015-03-31 12:37:00
如果您使用CI 3.xx版本,那么可以使用
$this->db->group_start();
while($i <= 6) {
$this->db->or_where('timetable_id',$this->input->post('timetable_id'.$i));
$i++;
}
$this->db->group_end();
$this->db->where('et.exam_name_id',5); 在字符串中的CI 2.xx版本传递条件中
发布于 2015-03-31 11:57:00
你让自己很难使用那个while循环。另外,如果你用循环构建数字,我也不明白你为什么要使用$this->input->post()。我会使用像这样的for循环:
for ($i = 1; $i <= 6; $i++) {
$this->db->or_where('timetable_id', $i);
}
$this->db->where('et.exam_name_id', 5);https://stackoverflow.com/questions/29367700
复制相似问题