1

那是我的选择功能:

 public function search($for) {
    $q = $this->select()->from($this->_name, array('id', 'title', 'content'))
            ->where('title LIKE ?', "%$for%")
            ->orWhere('content LIKE ?', "%$for%")
            ->orWhere('keywords LIKE ?', "%$for%")
            ->where('is_visible = ?', 0)
            ->where('category = ?', 7);

    return $this->fetchAll($q);
}

但是为什么如果 is_visible = 1 或 category 不同于 7 select 和其他行呢?

4

1 回答 1

2

我怀疑 AND/OR 优先级没有被正确解释。尝试这个:

$q = $this->select()->from($this->_name, array('id', 'title', 'content'))
        ->where("title LIKE '%$for%' OR content LIKE '%$for%' OR keywords LIKE '%$for%'")
        ->where('is_visible = ?', 0)
        ->where('category = ?', 7);
于 2012-09-10T16:50:13.903 回答