Solved

[Zend / Postgresql] Select query using limit and offset

Posted on 2009-07-14
2
1,582 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.

717 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