Zend Framework:选择查询

时间:2012-09-10 16:41:47

标签: php zend-framework

这是我的选择功能:

 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或类别与7选择和其他行不同?

1 个答案:

答案 0 :(得分: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);