troubleshooting Question

Form Filter not working

Avatar of Robert Granlund
Robert GranlundFlag for United States of America asked on
DatabasesPHPSQL
4 Comments1 Solution320 ViewsLast Modified:
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>
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 4 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros