Link to home
Start Free TrialLog in
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);
	$paginator->setCurrentPageNumber($this->_getParam('page'));
	$paginator->setItemCountPerPage(50);

	$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;	
}



var_dump($availableProperties);
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') ?>
	</div>

	<?php endif; ?>
</div>
</form>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Robert Granlund

ASKER

These are very helpful.  However, is there anything in the script that is causing it to paginate in that manner?
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.
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.