Solved

[Zend / Postgresql] Select query using limit and offset

Posted on 2009-07-14
2
1,566 Views
Last Modified: 2013-11-10
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
Comment
Question by:R7AF
2 Comments
 
LVL 14

Accepted Solution

by:
flob9 earned 500 total points
ID: 24847228
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
 
LVL 13

Author Closing Comment

by:R7AF
ID: 31603167
Thank you!
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
PHP AJAX JSON 2 61
Php recording post 4 53
What does $selected = $month == $beginning_month ? 'selected' : ''; mean? 5 32
How is this connection happening? 3 15
These days socially coordinated efforts have turned into a critical requirement for enterprises.
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question