• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 305
  • Last Modified:

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

  • 2
  • 2
1 Solution
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.
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.
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.

Join & Write a Comment

Featured Post

Get 10% Off Your First Squarespace Website

Ready to showcase your work, publish content or promote your business online? With Squarespace’s award-winning templates and 24/7 customer service, getting started is simple. Head to Squarespace.com and use offer code ‘EXPERTS’ to get 10% off your first purchase.

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