Adaptable Pagination and URL Query Builder with PHP 5

If you have to find pagination solutions for different window sizes or conditions 'Adaptable Pagination with PHP 5' makes it easy for you to the set correct variables: Adjust the demanded number of list rows and steps in no time - just changing two numbers. The Pagination Class calculates the position by using the array_chunk function from PHP which allows to cut an array in pieces, deciding what to do when stepping up or down the pagination (see screenshots below). Different functions handle the pagination status: do we need an extra last page or do we need flexible positions (several pages) or is a fixed one enough (first and last page)? The URL Query Builder (using RecursiveArrayObject and RecursiveIteratorIterator) is quiet similar to the http_build_query from PHP but junks empty variables and has a simple approach using arrays for query building.

The scripts snippets you see here (the complete script is downloadable) is only a small part of the complete script. That's it. All stuff is all prepared for your convenience (example with necessary files included). Best regards Claudio Biesele


Part of the Pagination Class Code :

public function paginationFlex() {
  if ($this->ab == 0 && $this->me == 0 || $this->ab == 0 && $this->me != 0) {
    $this->ab = $this->listrows;
    $this->values = range($this->startrange,$this->totalrecords);
    $this->setpos = $this->listrows;
  if ($this->ab != 0 && $this->me != 0) {
    if ($this->pos == $this->listrows) {
        $this->values = range($this->startrange,$this->totalrecords);
    }
    if ($this->pos > $this->listrows) {
      if ($this->getpos == 0) {
         $this->getpos = ($this->pos-$this->listrows)+1;
         $this->persistvalue = 1;
    }
    $this->values = range($this->getpos,$this->totalrecords);
   }
  }
}



Picture pagination_1.jpg
Example 1: Severals thousands of records spread on groups of 9 steps. First page and last page (overhang) are separated.
Picture pagination_2.jpg
Example 2: Last page and overhang with 15 records plus empty form elements.
Picture pagination_3.jpg
Example 3: Last page and overhang plus 15 records with filled in form elements.
Picture pagination_4.jpg
Example 4: Somewhere in between after form values are transferred by URL Query Builder to pagination.

Download the full script at www.fastproject.ch. The downloaded script is free from Copyright restrictions, Zurich, 03th of March 2015.
Donate with PayPal:
placeholder