gpt4 book ai didi

php - codeigniter 的 sql 查询

转载 作者:行者123 更新时间:2023-11-30 23:04:44 26 4
gpt4 key购买 nike

如何构建如下查询

SELECT 
*
FROM
propertylist
WHERE
(propertyfor = 'RENT')
AND (state LIKE '%AA%' OR city LIKE '%AA%'
OR address1 LIKE '%AA%'
OR description LIKE '%AA%'
OR address2 LIKE '%AA%')
ORDER BY transdt DESC

在 codeigniter 中?

我喜欢

$this->db->where('propertyfor',$type);
$this->db->like('state',$val);
$this->db->or_like('city',$val);
$this->db->or_like('address1',$val);
$this->db->or_like('description',$val);
$this->db->or_like('address2',$val);
$this->db->order_by('transdt', 'DESC');

$query = $this->db->get('propertylist');

有什么帮助吗?

最佳答案

试试这段代码:

$this->db->where('propertyfor', $type, FALSE);
$this->db->where("state LIKE '%{$val}%' OR city LIKE '%{$val}%'
OR address1 LIKE '%{$val}%'
OR description LIKE '%{$val}%'
OR address2 LIKE '%{$val}%'", NULL, FALSE);
$this->db->order_by('transdt', 'DESC');

$query = $this->db->get('propertylist');

更新:不幸的是,Codeigniter 没有其他方法可以在何处、来自何处或任何其他地方实现复杂的条件。您的代码:

$this->db->where('propertyfor',$type);
$this->db->like('state',$val);
$this->db->or_like('city',$val);
$this->db->or_like('address1',$val);
$this->db->or_like('description',$val);
$this->db->or_like('address2',$val);

通过 Codeigniter 转换为 SQL:

WHERE propertyfor = {$type}
AND state LIKE {$val}
OR city LIKE {$val}
OR address1 LIKE {$val}
OR description LIKE {$val}
OR address2 LIKE {$val}

关于php - codeigniter 的 sql 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22370976/

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