gpt4 book ai didi

php - 这个 codeigniter 查询如何执行?

转载 作者:行者123 更新时间:2023-11-29 12:28:33 25 4
gpt4 key购买 nike

这是(1)吗:

SELECT `message`, `from` FROM (`chat_messages`) WHERE `from` = '1' AND `delivered` = 1 OR `to` = '1' AND `delivered` = 1

与此(2)相同

SELECT `message`, `from` FROM (`chat_messages`) WHERE (`from` = '1' AND `delivered` = 1) OR (`to` = '1' AND `delivered` = 1) 

我用来生成结果 (1) 的 codeigniter 方法链式查询是

$this->db->select('message,from')->from('chat_messages')->where(array('from' => $user, 'delivered' => 1))->or_where('to', $user)->where('delivered', 1);

并生成(2)我用了这个

$where = "(`from` = '1' AND `delivered` = 1) OR (`to` = '1' AND `delivered` = 1)";
$this->db->select('message,from')->from('chat_messages')->where($where);

有人可以解释一下(从上面)编写 CI 查询的最佳方法吗?在第一个示例中 AND 是否获得第一优先级?

最佳答案

$this->db->select('message,from')->from('chat_messages')->where(array('from' => $user, 'delivered' => 1))->or_where('to', $user)->where('delivered', 1);

此代码使查询类似于

from = 'something' 并交付='something' 或 to='something' 并交付='something'

因此它会根据您的预期结果产生错误的结果。第四个是正确的。你可以使用它。

关于php - 这个 codeigniter 查询如何执行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27937985/

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