【问题标题】:Codeigniter where statement with parenthesis带括号的 Codeigniter where 语句
【发布时间】:2014-11-24 14:46:27
【问题描述】:

我要做的是在 where 语句中设置一个括号。像这样的:

SELECT
    `a_id`
FROM
    `auctions`
WHERE
    `a_state` = 1
AND (
    `p_name` LIKE '%XXX%'
    OR `at_name` LIKE '%XXX%'
    OR `p_code` LIKE '%XXX%'
)

但我不想这样做

$this->db->query('SELECT  `a_id` FROM `auctions` WHERE  `a_state` =1 AND (`p_name` LIKE  '%XXX%' OR `at_name` LIKE  '%XXX%' OR  `p_code` LIKE  '%XXX%');

我想使用活动记录类。

有什么想法吗?

谢谢

【问题讨论】:

标签: mysql codeigniter where


【解决方案1】:
$where="`a_state` =1 AND (`p_name` LIKE  '%XXX%' OR `at_name` LIKE  '%XXX%' OR  `p_code` LIKE  '%XXX%')";

    $this->db->select('a_id');
    $this->db->where($where);
    $this->db->from('auctions');
    $query = $this->db->get('');
echo  $this->db->last_query();// print the last query

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-06-15
    • 2017-06-14
    • 2012-07-02
    • 1970-01-01
    • 2017-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-08-15
    相关资源
    最近更新 更多