probelma paginazione dati

luigi777

Utente Attivo
14 Feb 2008
1.086
1
38
43
Massa, Italy
Salve, ho un problema che non mi riesce ad risolvere di una classe che crea la paginazione..
il problema che se io manualmente metto:

http://localhost/nomesito/index.php?m=news&pagina=%
il simbolo %
mi salta fuori:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-1, 1' at line 1

Questa è la classe:
PHP:
<?php
	class Paginazione
	{
		private $xpage = 0;
		private $tot = 0;
		private $varq = "";
		private $totpag = 0;
		private $cpage = 0;
		private $query = "";
		private $record = array();
	
		public function Paginazione($query, $xpage, $varq)
		{
			// le rendo globali
			$this->xpage = $xpage;
			$this->varq = $varq;
			$this->query = trim($query);
			
			// pagina corrente sia get che post
			$this->cpage = (isset($_REQUEST[$varq])) ? (int)$_REQUEST[$varq] : 1;
			
			// inizio record
			$inizio = $xpage * ($this->cpage - 1);
			
			// eseguo la query per contare i record
			$ct = mysql_query($this->query) or die(mysql_error());
			
			// record totali
			$this->tot = mysql_num_rows($ct);
			
			// se ci sono record
			if($this->tot > 0)
			{
				// pagine totali
				$this->totpag = ceil($this->tot / $xpage);
				
				//Pagina di inizio
			
				
				
				
				// scrivo ed eseguo la query mirata
				$target = " LIMIT " . $inizio . ", " . $xpage;
				$ex = mysql_query($this->query . $target) or die(mysql_error());
				
				while($ft = mysql_fetch_array($ex, MYSQL_ASSOC))
				{
					$record[] = $ft;
				}
				
				$this->record = $record;
			}
			else
			{
				$this->record = array();
			}
		}
		
		public function Show()
		{
			if(count($this->record) > 0)
			{
				return $this->record;
			}
			else
			{
				return false;
			}
			
		}
		
		public function Link($nlink = 4)
		{
			$before = array();
			$after = array();
			
			if($this->cpage < $nlink)
			{
				$nlink *= 2;
				$nlink -= ($this->cpage - 1);
			}
			elseif($this->cpage > ($this->totpag - $nlink))
			{
				$nlink *= 2;
				$nlink -= ($this->totpag - $this->cpage);
			}
			
			
			
			for($i = $nlink; $i>=1; $i--)
			{
				if(($this->cpage - $i) >= 1)
				{
					$before[] = $this->cpage - $i;
				}
			}
			
			for($i = 1; $i<=$nlink; $i++)
			{
				if(($this->cpage + $i) <= $this->totpag)
				{
					$after[] = $this->cpage + $i;
				}
				
				if($this->cpage == $nlink)
					$nlink += 1;
			}
			
			$link["first"] = 1;
			$link["before"] = $before;
			$link["current"] = $this->cpage;
			$link["after"] = $after;
			$link["last"] = $this->totpag;
			
			if($this->cpage <= $this->totpag && $this->totpag > 1)
			{
				return $link;
			}
			else
			{
				return false;
			}
		}
	}
?>

non riesco ad mettere il controllo alla paginazione che ho trovato su internet..

il controllo per far che non venga passato altri dati testuali che non siano numeri.



ha scordavo la paginazione si usa cosi:

PHP:
	$strSQL = "SELECT  news_sezioni.strNome as strNomeSezione , news.* FROM news INNER JOIN news_sezioni ON news_sezioni.intSezioneID = news.intSezioneID";
	$pag = new Paginazione($strSQL,$cfg_news_per_page_admin, "pagina");

mi dite come posso fare?.
grazie mille.
 
niente da fare.. mi potete risolvere il problema con questa classe??

perché non trovo una classe decente come questa.

per favore .. grazie mille.
 

Discussioni simili