gpt4 book ai didi

php - AND 和 OR 子句的组合

转载 作者:行者123 更新时间:2023-11-29 08:26:10 28 4
gpt4 key购买 nike

我想在CodeIgniter中实现以下mysql语句。

select * from table_name 
where deleted = 0 and (id = "18" or name = "efgh" or imei = "1244");

我在 CodeIgniter 中编写了以下语句:

$this->db->where('deleted', 0);
$this->db->or_where('id', $this->table_name->id);
$this->db->or_where('imei', $this->table_name->imei);
$this->db->or_where('name', $this->table_name->name);
$result= $this->db->get('table_name')->result();

但是这两个语句给出了不同的输出。任何人都可以指出CodeIgniter声明中的错误吗?谢谢。

最佳答案

请使用这个:-

   $where = "deleted='0' AND (id='18' OR name='efgh' OR imei='1244')";
$this->db->where($where);
$result= $this->db->get('table_name')->result();

欲了解更多详情,您可以访问:-

http://ellislab.com/codeigniter/user-guide/database/active_record.html

关于php - AND 和 OR 子句的组合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17851647/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com