[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

LVL 13
R7AFAsked:
Who is Participating?
 
flob9Connect With a Mentor Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.