Form Filter not working

The following code is built on the Zend Framework.  The form and script work fine.  However, there is a weird thing that I don't understand.

If I use the form and choose Alhambra, it will return aprox 68 records.  I have to pagination set to 50 records.  When I click the next button, it returns the second 50 records from the DB as if I had not chosen a location.  THEN is I choose Alhambra again and filter, it will show me the additional records left for Alhambra.

What I want the script to do is if I choose Alhambra, see all Alhambra records (first 50) paginate to the next page and see the remainder of the records and then see all of the other records in the DB.  So I want to order by Alhambra and keep alhambra chosen when I paginate to the next page.

public function pnlsAction()
	$db = Stax_Db::getConnection();
	$where = array();
	if (is_numeric($this->_getParam('property'))) {
		$where[] = 'property_id = ' . $db->quote($this->_getParam('property'), Zend_Db::INT_TYPE);
		$this->view->property = $this->_getParam('property');
	//if(isset($_POST['property'])) {echo 'value="'.$_POST['property'].'"'; $where[] = $_POST['property'];}
	$where = count($where) ? $where : $this->getProps($db);

	$records = $this->user->getAllPNLs(implode(' OR ',$where));

	$paginator = Zend_Paginator::factory($records);

	$availableProperties = array();
	if ($this->user->access != Stax_User::ACCESS_ADMIN) {
		foreach ($this->user->getProperties() as $current) {
			$availableProperties[$current->property_id] = $current->name;
	} else {
		$availableProperties = $db->fetchPairs("SELECT property_id, name FROM properties WHERE active = '1' ORDER BY name ASC");
	$availableProperties = array(''=>'Select a Property') + $availableProperties;
	$this->view->properties = $availableProperties;
	$this->view->paginator = $paginator;	

array(56) { [""]=> string(17) "Select a Property" 
[42]=> string(8) "Alhambra" 
[49]=> string(7) "Banning" 
[1]=> string(7) "Barstow" 
[25]=> string(16) "Bedford Pancakes" 
[4]=> string(7) "Boulder" 
[19]=> string(8) "Brighton" 
[62]=> string(8) "Brockton" 
[22]=> string(8) "Brooklyn" 
[30]=> string(7) "Burbank"
etc...etc... } 

This is the form:
<form method="post" action="">
<div class="filter-bar">
	<?php if ($this->user->access != Stax_User::ACCESS_MANAGER) : ?>
	<div>Property: <?= $this->formSelect('property', $this->property, array('style'=>'width:150px'), $this->properties); ?></div>

	<div style="float:right">
		<?= $this->formSubmit(null, 'Filter') ?>

	<?php endif; ?>

Open in new window

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ray PaseurCommented:
I think the Zend part of this may be getting in the way of learning the basics.  This article from SitePoint, though old, is still the canonical article about pagination.

Basically, your WHERE clause needs to store the Alhambra designation, and your LIMIT clause needs to store the row number and row count.  Obviously ORDER BY is important, too.  These things are documented in the MySQL data base online manuals and at various learning reference sites.

Some variants of SQL use TOP instead of LIMIT.  MySQL is a little more flexible in this regard.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rgranlundAuthor Commented:
These are very helpful.  However, is there anything in the script that is causing it to paginate in that manner?
Ray PaseurCommented:
I don't know; there are a lot of lines omitted from the code snippet.  Maybe if you can reduce it to the SSCCE (something we can install and use to replicate the failure) we can begin to tease it apart.
rgranlundAuthor Commented:
I appreciate all of your help. After doing a boat load of research I've learned that this is the way Zend Pagination works out of the box.  It seems counter intuitive to me but hey, that's the way it is.  So, instead of creating new classes, views and controllers, I decided to append the query result to the url and use $_GET to keep it working correctly.  I was hoping to figure out a better, cleaner way to do it, but lost interest in Zend Pagination for the moment.

Again, thanks.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.