problema paginazione con valori -1 -2 -3 -4

luigi777

Utente Attivo
14 Feb 2008
1.086
1
38
42
Massa, Italy
Salve, ho questa classe che ho trovato che mi serve per fare la paginazione dei dati..

ora ho un problema se uno digita prova.php?p=-1 mi da errore Syntax error or access violation

ve la posto:

PHP:
<?php
/*
 * PHP Pagination Class
 *
 * @author David Carr - [email protected] - http://www.daveismyname.com
 * @version 1.0
 * @date October 20, 2012
 */
class Paginator{

        /**
	 * set the number of items per page.
	 *
	 * @var numeric
	*/
	private $_perPage;

	/**
	 * set get parameter for fetching the page number
	 *
	 * @var string
	*/
	private $_instance;

	/**
	 * sets the page number.
	 *
	 * @var numeric
	*/
	private $_page;

	/**
	 * set the limit for the data source
	 *
	 * @var string
	*/
	private $_limit;

	/**
	 * set the total number of records/items.
	 *
	 * @var numeric
	*/
	private $_totalRows = 0;



	/**
	 *  __construct
	 *  
	 *  pass values when class is istantiated 
	 *  
	 * @param numeric  $_perPage  sets the number of iteems per page
	 * @param numeric  $_instance sets the instance for the GET parameter
	 */
	public function __construct($perPage,$instance){
		$this->_instance = $instance;		
		$this->_perPage = $perPage;
		$this->set_instance();		
	}

	/**
	 * get_start
	 *
	 * creates the starting point for limiting the dataset
	 * @return numeric
	*/
	private function get_start(){
		return ($this->_page * $this->_perPage) - $this->_perPage;
	}

	/**
	 * set_instance
	 * 
	 * sets the instance parameter, if numeric value is 0 then set to 1
	 *
	 * @var numeric
	*/
	private function set_instance(){
		$this->_page = (int) (!isset($_GET[$this->_instance]) ? 1 : $_GET[$this->_instance]); 
		$this->_page = ($this->_page == 0 ? 1 : $this->_page);
	}

	/**
	 * set_total
	 *
	 * collect a numberic value and assigns it to the totalRows
	 *
	 * @var numeric
	*/
	public function set_total($_totalRows){
		$this->_totalRows = $_totalRows;
	}

	/**
	 * get_limit
	 *
	 * returns the limit for the data source, calling the get_start method and passing in the number of items perp page
	 * 
	 * @return string
	*/
	public function get_limit(){
        	return "LIMIT ".$this->get_start().",$this->_perPage";
        }

        /**
         * page_links
         *
         * create the html links for navigating through the dataset
         * 
         * @var sting $path optionally set the path for the link
         * @var sting $ext optionally pass in extra parameters to the GET
         * @return string returns the html menu
        */
	public function page_links($path='?',$ext=null)
	{
	    $adjacents = "2";
	    $prev = $this->_page - 1;
	    $next = $this->_page + 1;
	    $lastpage = ceil($this->_totalRows/$this->_perPage);
	    $lpm1 = $lastpage - 1;

	    $pagination = "";
		if($lastpage > 1)
		{   
		    $pagination .= "<div class='pagination'>";
		if ($this->_page > 1)
		    $pagination.= "<a href='".$path."$this->_instance=$prev"."$ext'>« previous</a>";
		else
		    $pagination.= "<span class='disabled'>« previous</span>";   

		if ($lastpage < 7 + ($adjacents * 2))
		{   
		for ($counter = 1; $counter <= $lastpage; $counter++)
		{
		if ($counter == $this->_page)
		    $pagination.= "<span class='current'>$counter</span>";
		else
		    $pagination.= "<a href='".$path."$this->_instance=$counter"."$ext'>$counter</a>";                   
		}
		}
		elseif($lastpage > 5 + ($adjacents * 2))
		{
		if($this->_page < 1 + ($adjacents * 2))       
		{
		for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++)
		{
		if ($counter == $this->_page)
		    $pagination.= "<span class='current'>$counter</span>";
		else
		    $pagination.= "<a href='".$path."$this->_instance=$counter"."$ext'>$counter</a>";                   
		}
		    $pagination.= "...";
		    $pagination.= "<a href='".$path."$this->_instance=$lpm1"."$ext'>$lpm1</a>";
		    $pagination.= "<a href='".$path."$this->_instance=$lastpage"."$ext'>$lastpage</a>";       
		}
		elseif($lastpage - ($adjacents * 2) > $this->_page && $this->_page > ($adjacents * 2))
		{
		    $pagination.= "<a href='".$path."$this->_instance=1"."$ext'>1</a>";
		    $pagination.= "<a href='".$path."$this->_instance=2"."$ext'>2</a>";
		    $pagination.= "...";
		for ($counter = $this->_page - $adjacents; $counter <= $this->_page + $adjacents; $counter++)
		{
		if ($counter == $this->_page)
		    $pagination.= "<span class='current'>$counter</span>";
		else
		    $pagination.= "<a href='".$path."$this->_instance=$counter"."$ext'>$counter</a>";                   
		}
		    $pagination.= "..";
		    $pagination.= "<a href='".$path."$this->_instance=$lpm1"."$ext'>$lpm1</a>";
		    $pagination.= "<a href='".$path."$this->_instance=$lastpage"."$ext'>$lastpage</a>";       
		}
		else
		{
		    $pagination.= "<a href='".$path."$this->_instance=1"."$ext'>1</a>";
		    $pagination.= "<a href='".$path."$this->_instance=2"."$ext'>2</a>";
		    $pagination.= "..";
		for ($counter = $lastpage - (2 + ($adjacents * 2)); $counter <= $lastpage; $counter++)
		{
		if ($counter == $this->_page)
		    $pagination.= "<span class='current'>$counter</span>";
		else
		    $pagination.= "<a href='".$path."$this->_instance=$counter"."$ext'>$counter</a>";                   
		}
		}
		}

		if ($this->_page < $counter - 1)
		    $pagination.= "<a href='".$path."$this->_instance=$next"."$ext'>next »</a>";
		else
		    $pagination.= "<span class='disabled'>next »</span>";
		    $pagination.= "</div>\n";       
		}


	return $pagination;
	}
}

mi dite se con un (int), semplice si risolve il problema?

perché ho utilizzato questa classe in tutto il mio sito..se mi dite dove sta il problema mi fate un regalo..


avete idea?

grazie mille e buona settimana.
 
Discussioni simili
Autore Titolo Forum Risposte Data
MarcoGrazia Problema con bootstrap, saltata tutta la paginazione in IE8 HTML e CSS 1
M Problema Paginazione con Mod_rewrite .htaccess PHP 0
W Problema eliminazione ultimo record da ultima pagina di crud con paginazione PHP 2
A [PHP] Problema paginazione motore di ricerca PHP 48
G Problema di Indice e Paginazione PHP 5
M Problema su numerazione paginazione php PHP 6
L Problema paginazione che ripete i dati doppi PHP 1
L Problema classe paginazione PHP 2
A paginazione problema LIMIT PHP 2
C problema paginazione php PHP 2
M problema paginazione PHP 0
S Problema di paginazione Classic ASP 1
K Problema form update PHP 2
O problema con dvr dahua xvr5116 IP Cam e Videosorveglianza 0
S Problema nel ciclare un json Javascript 0
G Problema con Xampp Web Server 1
andrea barletta Problema con miniature comandi Photoshop 0
I problema con alice Posta Elettronica 0
K Problema Inner join PHP 1
F firefox problema http Linux e Software 0
N Problema con position absolute e overflow HTML e CSS 4
E Problema jquery Success jQuery 2
L Problema con inner join PHP 11
K [php] Problema con inner join PHP 4
E problema selezione sfumata Photoshop 2
K [PHP] Problema con variabili concatenate. PHP 1
A Problema filtro fluidifica Photoshop Photoshop 1
H Problema Bordi Scontorno Photoshop 1
O problema con query PHP 4
R Problema installazione Realtek WiFi USB rtl8821 Reti LAN e Wireless 0
I problema con 2 account Posta Elettronica 1
L problema collegamento file css con html HTML e CSS 1
Y Problema percorso file in rete PHP 1
N Problema SEO "L'URL non si trova su Google" SEO e Posizionamento 4
E Problema accesso a file con app sviluppata con MIT APP INVENTOR 2 Sviluppo app per Android 0
P Problema acquisizione clienti Webdesign e Grafica 1
F NetBeans problema creazione progetto Java Windows e Software 0
M Problema con Try Catch PHP 0
C problema seo + cerco esperto SEO e Posizionamento 11
Sergio Unia Problema con gli eventi del mouse su una data table: Javascript 2
T PROBLEMA CON SESSIONI PHP 3
A Problema, non so, di scale() o transform, oppure altro? HTML e CSS 0
T ALTRO PROBLEMA CON ARRAY PHP PHP 1
R problema con else PHP 0
T PROBLEMA CON ARRAY PHP 8
L problema con query select PHP 2
R Problema query con ricerca id numerico PHP 2
F Problema con risposta PHP 0
S problema con recupero dati tabella mysql PHP 2
Z Problema con il mio tp-l i nk Reti LAN e Wireless 1

Discussioni simili