douxuelv7755 2019-01-03 14:38
浏览 82
已采纳

如何在moodle中为现有查询添加类似条件

I have a query with multiple conditions check. I want to add the condition to check the with like clause. I tried like this.

$params1['email'] =$DB->sql_like('email', '%'.$voucher_query.'%');

and I am passing the params1 value to query condition. I am getting the query as different and it is not working. This is the query I am getting.

SELECT COUNT('x') FROM tbl_order WHERE active_ind = ? AND id = ? AND email = ? [array ( 0 => 1, 1 => 236909, 2 => 'email LIKE %emelchor% COLLATE utf8_bin ESCAPE \'\\\\\'', )]

the email condition is checking with equals to but not with like exactly. Can anyone help me out.?

Thanks in advance

  • 写回答

1条回答 默认 最新

  • dongtuo0828 2019-01-03 15:44
    关注

    You haven't shown the function call you are doing to retrieve the records, but I'm guessing it looks something like:

    $DB->get_records('order', $params);
    

    This simple DB syntax is only suitable for equals comparisons, if you want to do something more complex, you will need to rewrite it to use the get_records_select function instead, e.g.

    $select = 'active_ind = :ind AND id = :id AND '.$DB->sql_like('email', ':email');
    $email = '%'.$DB->sql_like_escape($voucher_query).'%';
    $params = ['ind' => $ind, 'id' => $id, 'email' => $email];
    $result = $DB->get_records_select('order', $select, $params);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 请提供一个符合要求的网页链接。
  • ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”
  • ¥15 网络设备配置与管理这个该怎么弄
  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码