<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[[Script] Classe per l'impaginazione]]></title><description><![CDATA[<p dir="auto">Ciao a tutti!<br />
Per esigenza su un mio script, ho dovuto creare una semplice classe per l'impaginazione, ed ho pensato che forse potrebbe esservi utile.<br />
Ecco la classe:<br />
class.pagination.php</p>
<pre><code class="language-php">&lt;?php
//CLASSE DI IMPAGINAZIONE
class impaginazione{
public $menu;
public $num_per_page;
public $ceil;
public $from;
public $query;
public $rows;
function createlink($page,$num_per_page,$query,$rows,$url){
$this-&gt;page = $page;
$this-&gt;num_per_page = $num_per_page;
$this-&gt;query = $query;
$this-&gt;rows = $rows;
$this-&gt;url = $url;

$this-&gt;ceil = ceil($this-&gt;rows/$this-&gt;num_per_page);
$this-&gt;from = (($this-&gt;page * $this-&gt;num_per_page) - $this-&gt;num_per_page);
$this-&gt;menu = "";

if($this-&gt;page &gt; 1)
{
$this-&gt;menu .= " &lt;a href=\"".$this-&gt;url."&amp;amp;page=".($page-1)."\"&gt;Indietro&lt;/a&gt; ";
}

for($i = 1; $i &lt;= $this-&gt;ceil; $i++)
{
if(($this-&gt;page) == $i)
{
$this-&gt;menu .= $i;
}
else
{
$this-&gt;menu .= " &lt;a href=\"".$this-&gt;url."&amp;amp;page=".$i."\"&gt;$i&lt;/a&gt; ";
}
}
if($this-&gt;page &lt; $this-&gt;ceil)
{
$this-&gt;menu .= " &lt;a href=\"".$this-&gt;url."&amp;amp;page=".($page+1)."\"&gt;Avanti&lt;/a&gt; ";
}
$this-&gt;query .= " LIMIT  ".$this-&gt;from.",".$this-&gt;num_per_page."";//COMPLETA LA QUERY
}
}
?&gt;
</code></pre>
<p dir="auto">Ecco l'utilizzo:</p>
<pre><code class="language-php">&lt;?php
////////////////////////////
#IMPAGINAZIONE#
###########################
require "class.pagination.php";
$page = (!isset($_GET['page'])) ? 1 : $_GET['page'];//controlli necessari
$page =($page == 0) ? 1 : $_GET['page'];//controlli necessari
#Qui eseguiamo la query che recupera i dati
#Ricordate che la query non deve contenere il carattere LIMIT
$query_init ="SELECT * FROM snf_topics WHERE snf_t_forumid = '" . $_GET['fs'] . "' ORDER BY snf_t_id DESC";//La nostra query(in questo caso la mia)
$action = mysql_query($query_init);//ESEGUE
$rows = mysql_num_rows($query_init);//Il numero di colonne, dato importantissimo
$num_per_page = 10;//quanti articoli vogliamo per ogni pagina

$pag = new impaginazione();//creo nuova istanza
$link = "show.php?fs=".$_GET['fs'];//La pagina su cui lo script deve agire(es index.php?var1=1 diventerà index.php?var1=1&amp;page=1)

$pag-&gt;createlink($page,$num_per_page,$query_init,$rows,$link);

$query = mysql_query($pag-&gt;query);
$menu = $pag-&gt;menu;
while($row = mysql_fetch_array($query)){
....
}
echo $menu;
//Formato: Indietro 1 2 3 4 Avanti

?&gt;
</code></pre>
<p dir="auto">Spero di essere stato utile</p>
]]></description><link>https://dev.connect.gt/topic/90650/script-classe-per-l-impaginazione</link><generator>RSS for Node</generator><lastBuildDate>Thu, 26 Nov 2026 01:55:04 GMT</lastBuildDate><atom:link href="https://dev.connect.gt/topic/90650.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 22 Dec 2008 12:41:53 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to [Script] Classe per l'impaginazione on Wed, 02 Sep 2009 12:09:22 GMT]]></title><description><![CDATA[<p dir="auto">Ciao... Lo script non funziona!! Mi dà errore nella creazione della funzione... Non esiste qualche script simile a questo ma più semplice?</p>
]]></description><link>https://dev.connect.gt/post/793910</link><guid isPermaLink="true">https://dev.connect.gt/post/793910</guid><dc:creator><![CDATA[dj.teto]]></dc:creator><pubDate>Wed, 02 Sep 2009 12:09:22 GMT</pubDate></item><item><title><![CDATA[Reply to [Script] Classe per l'impaginazione on Sat, 27 Dec 2008 20:58:40 GMT]]></title><description><![CDATA[<p dir="auto">Appena posso la provo! <img src="https://dev.connect.gt/assets/plugins/nodebb-plugin-emoji/emoji/customizations/8d7b9529-9868-4606-8ca1-85ca7d28c845-wink.gif?v=12b9555a9a1" class="not-responsive emoji emoji-customizations emoji--wink3" style="height:1.4em;width:auto;vertical-align:middle" title=":wink3:" alt="" /></p>
]]></description><link>https://dev.connect.gt/post/793909</link><guid isPermaLink="true">https://dev.connect.gt/post/793909</guid><dc:creator><![CDATA[ciccio6630]]></dc:creator><pubDate>Sat, 27 Dec 2008 20:58:40 GMT</pubDate></item></channel></rss>