Jump to content

Limit not working?


Tom.
 Share

Recommended Posts

I'm trying to order a search by two ways:
1) Does this contain the search string? If so display first. (The rest is based on the geolocated postal code)
2) The user chosen order (price etc.)

 

To do this, I have done the following:

$properties = $pages->find("template=property$selector");
	
	if($locality) {
		foreach($properties as $property) {
			if($property->is("address~=$locality")) $property->nearby = 1; else $property->nearby = 0;
		}
	}
	
	$properties = $properties->find("sort=-nearby, sort=$sort_order, limit=25");
	$pagination = $properties->renderPager(array("nextItemLabel" => "Next <i class='icon-right'></i>","previousItemLabel" => "<i class='icon-left'></i> Prev"));

 

However, $pagination is not working in this example. I've tried both ->find and ->filter. $pagination seems to be ignoring this, nor is the limit taking place.

 

Is there an easier way of doing this?

 

EDIT:

The following works, however I would very much like to know if there is a way to do this in a singular selector? I worry about performance issues when not limiting the results from MySQL.

	$limit = 24;
	$start = ($input->pageNum - 1) * $limit;
	$properties = $properties->find("sort=-nearby, sort=$sort_order, start=$start, limit=$limit");
	
	$properties->setStart($start);
	$properties->setLimit($limit);
	$pagination = $properties->renderPager(array("nextItemLabel" => "Next <i class='icon-right'></i>","previousItemLabel" => "<i class='icon-left'></i> Prev"));

 

Link to comment
Share on other sites

Check out the brilliant Paginator by @LostKobrakai: https://github.com/LostKobrakai/Paginator/

I mentioned Paginator in a post yesterday but I hadn't used it at that point. I've just tried it out and it works a treat for when you want to paginate the results of two or more $pages->find() operations. There aren't any detailed instructions yet but the example in the readme should be enough to go on.

So for your case you want to avoid the foreach and instead create two separate selectors for use in Paginator. Something like:

include 'src/Paginator.php';
include 'src/PagesPaginator.php';

$paginator = new PagesPaginator();

$result = $paginator(array(
    "template=property$selector, address~=$locality, sort=$sort_order",
    "template=property$selector, !address~=$locality, sort=$sort_order"
), $input->pageNum, 25);

 

  • Like 2
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...