Avatar of Robert Granlund
Robert GranlundFlag for United States of America asked on

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


Avatar of undefined
Last Comment
Robert Granlund

8/22/2022 - Mon
Ray Paseur

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Robert Granlund

These are very helpful.  However, is there anything in the script that is causing it to paginate in that manner?
Ray Paseur

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.
Robert Granlund

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.
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.