Jump to content

Set result limit using Get variable


Recommended Posts

Hi everybody,

I have got a (hopefully) pretty simple question but I can't find a "clean" solution for it and hope you can help me.

I'm using a form to let the user specify different variables (Get Request) and show them the according pages.

It's more or less similar to the Skyscraper Demo page.

Now I'd like to add three links to set the limit of my query. So if the user clicks on e.g. 10  -> only 10 pages should be listed (leaving the other variables the same).

I'd like to generate links with the current URL but change the limit variable.

Is there a function to get the current URL with all the get parameters and let me change/add one of them?

Or do you have any other suggestions how I could add this functionality?

Thanks for your help!

Link to comment
Share on other sites

I wanted to know if there is an easy way to generate the URLs for my links.

I'm now using plain PHP functionality:

$params = array_merge($_GET, array("limit" => 10));
$new_query_string = http_build_query($params);

Thanks for your help!

Link to comment
Share on other sites

Since you are pulling them right out of $_GET (or $input->get), you should filter and sanitize them before doing your http_build_query.

$types = array(
  'limit' => 0,
  'my_string_var' => '',
  'my_int_var' => 0, 

$params = array();

foreach($types as $name => $type) {
  $value = $input->get->$name; 
  if($value === null) continue; // not specified, skip over
  if(is_string($type)) $params[$name] = $sanitizer->text($value);  // sanitize as string
    else $params[$name] = (int) $value; // sanitizer as int

if(empty($params['limit'])) $params['limit'] = 10; // set a default

$new_query_string = http_build_query($params); 
  • Like 3
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

  • Create New...