1

我有一个查询要从 db 阅读杂志

$select = $db->select()
            ->from('tbl_magazine',array('magazine_id','magazine_name'))
            ->join('tbl_magazine_issue','tbl_magazine_issue.magazine_id = tbl_magazine.magazine_id',array(null))
            ->join('mst_publisher','mst_publisher.publisher_id = tbl_magazine.publisher_id',array(null))
            ->where('tbl_magazine.is_active =?',1)
            ->where('mst_publisher.is_active =?',1)
            ->where('tbl_magazine_issue.os_select =?',2)
            ->where('tbl_magazine_issue.publish_status = ?',1)
            ->where('curdate() <= DATE(tbl_magazine.validity_till)')
            ->group('tbl_magazine.magazine_id')
            ->limit($start,$per_page);

但是当我打印查询时,我看到了类似这样的东西

SELECT `tbl_magazine`.`magazine_id`, `tbl_magazine`.`magazine_name` 
FROM `tbl_magazine` 
INNER JOIN `tbl_magazine_issue` ON tbl_magazine_issue.magazine_id = tbl_magazine.magazine_id 
INNER JOIN `mst_publisher` ON mst_publisher.publisher_id = tbl_magazine.publisher_id 
WHERE (tbl_magazine.is_active =1) AND (mst_publisher.is_active =1) 
  AND (tbl_magazine_issue.os_select =2) AND (tbl_magazine_issue.publish_status = 1) 
  AND (curdate() <= DATE(tbl_magazine.validity_till)) 
GROUP BY `tbl_magazine`.`magazine_id` 
LIMIT 2147483647 OFFSET 8

但我已将 $start 设置为 0 并将 $perpage 设置为 8

我正在寻找一个限制为的查询"limit 0 ,8"

4

1 回答 1

5

你没有limit正确使用。

这是来自 的函数定义Zend_Db_Select。如您所见,第一个参数 iscount和 not offset

/**
 * Sets a limit count and offset to the query.
 *
 * @param int $count OPTIONAL The number of rows to return.
 * @param int $offset OPTIONAL Start returning after this many rows.
 * @return Zend_Db_Select This Zend_Db_Select object.
 */
public function limit($count = null, $offset = null)
{
    $this->_parts[self::LIMIT_COUNT]  = (int) $count;
    $this->_parts[self::LIMIT_OFFSET] = (int) $offset;
    return $this;
}


只是为了解释为什么你会得到那些疯狂的值......下面是呈现 SQL 查询的脚本的一部分。因为您有偏移量,所以将计数设置为 PHP_INT_MAX。

 if (!empty($this->_parts[self::LIMIT_OFFSET])) {
        $offset = (int) $this->_parts[self::LIMIT_OFFSET];
        $count = PHP_INT_MAX;
    }
于 2012-04-11T05:05:52.060 回答