简体   繁体   English

如何在杂货店合并和/或运算符

[英]How to combine and & or operators in grocery crud

I am using codeigniter and grocerycrud, I want to set a table with grocerycrud in this way: 我正在使用codeigniter和杂货店,我想用这种方式与杂货店一起摆一张桌子:

SELECT * FROM `dashboard`.`medidas_ludlum`
where FK_ludlum='190.26.88.131'
and date>= '2014-03-04 09:40:00'
and date<= '2014-03-05 09:40:00'
and (error_code=1 or audio_status=1);

I tried to do that in this way: 我试图通过这种方式做到这一点:

  $uno='1';
  $crud2 = new grocery_CRUD();
  $crud2->set_theme('datatables');
  $crud2->where('FK_ludlum',$ludlum_id);
  $crud2->where('date>=',$fechainicio);$crud2->where('date<=',$fechafin);
  $crud2->where('error_code =',$uno);
  $crud2->or_where('audio_status =',$uno);
  $crud2->set_table('medidas_ludlum');
  $crud2->columns('measurement', 'fecha', 'audio_status', 'high_alarm_status', 'low_alarm_status','over_range_status','monitor_status','error_code');
  $crud2->set_language("spanish");
  $crud2->unset_add();$crud2->unset_delete();$crud2->unset_edit();$crud2->unset_read();
  $data['crud2'] = $crud2->render();

However it's not giving the right results, for example I am getting rows that have a date out of the range, is there a way to get that CRUD set up? 但是,它没有给出正确的结果,例如,我得到日期超出范围的行,是否有办法设置CRUD?

Grocery curd is also using codeigniter's active record so you can write your where() with grouped conditions as below,no need to use or_where() function 杂货豆腐也使用了codeigniter的活动记录,因此您可以使用以下分组条件编写where() ,而无需使用or_where()函数

$crud2->where('(error_code ='.$uno.' OR audio_status ='.$uno.')',null,FALSE);

or 要么

$crud2->where('(error_code =1 OR audio_status =1)',null,FALSE);

The problem in your query is when you use or_where() function it produces where clause as and error_code=1 or audio_status=1 and using approach that i have provide will give you the where clause as and (error_code=1 or audio_status=1) a grouped condition 查询中的问题是,当您使用or_where()函数时,它将生成where子句为and error_code=1 or audio_status=1并且使用我提供的方法将为您提供where子句为and (error_code=1 or audio_status=1)分组条件

API and Functions list API和功能列表

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM