Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1616
  • Last Modified:

[Zend / Postgresql] Select query using limit and offset

I'm starting to use Zend Framework and would like to use a query with limit and offset, as the resultset is rather large. If I use the fetchLatest function (see below), I get 10 rows back. I have two questions about this:

1) If I use the fetchSubset function I get an error (Fatal error: Call to undefined method). I suppose I should import a library or something, but don't know how and what.
2) Is there a better method of using limit and offset than the query() function?
<?php
class Countries extends Zend_Db_Table
{
 
	function fetchLatest($count = 10)
	{
		return $this->fetchAll(null, 'id desc', $count); 
	}
 
	function fetchSubset($limit = 10, $offset = 0)
	{
		$sql = 'select * from countries order by id limit '.$limit.' offset ' . $offset;
		return $this->query($sql); 
	}

Open in new window

0
R7AF
Asked:
R7AF
1 Solution
 
flob9Commented:
Doesn't this work ? :

$table->fetchAll(null,'id desc', $count, $offset);

Or :

$select = $table->select()->order('id desc')->limit($count, $offset);
$rows = $table->fetchAll($select);
0
 
R7AFAuthor Commented:
Thank you!
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now