Ciao a tutti ragazzi,
ho questo problema per la numerazione delle pagine.
Devo praticamente numerare le pagine in base alla selezione di un argomento.
Il seguente codice mi fa vedere correttamente la prima pagina, ma quando accedo alla seconda non compare nulla e mi dice "pagina 2 di 0". Se torno alla prima pagina non mi compare nessun record...
Vi posto il codice
Codice PHP:
<?
include("config.inc.php");
$db = mysql_connect($db_host, $db_user, $db_password);
if ($db == FALSE)
die ("Errore nella connessione. Verificare i parametri nel file config.inc.php");
mysql_select_db($db_name, $db)
or die ("Errore nella selezione del database. Verificare i parametri nel file config.inc.php");
if (!isset($start) OR $start<0)
$start=0;
$step = 40;
$rowsPerPage = 3;
$pageNum = 1;
if(isset($_GET['page']))
{
$pageNum = $_GET['page'];
}
$offset = ($pageNum - 1) * $rowsPerPage;
$query = "SELECT id,titolo,data,testo,argomento FROM articoli WHERE argomento='$argomento' LIMIT $offset, $rowsPerPage";
$result = mysql_query($query, $db);
while(list($row[id], $row[titolo], $row[data], $row[testo], $row[argomento]) = mysql_fetch_array($result))
{
?>
<font face="Verdana" size="3"><font color="#b20521">[b] <?php echo "$row[titolo]"; ?>[/b] [/b]</font></font>
[b][i]<?php echo "$row[data]
"; ?>[/i][/b]
<?php echo "$row[testo]
";?>
<?php echo "$row[argomento]
";?>
</span>
</div>
<?php
}
$query = "SELECT COUNT(argomento) AS numrows FROM articoli WHERE argomento='$argomento' ";
$result = mysql_query($query, $db);
$row = mysql_fetch_array($result, MYSQL_ASSOC);
$numrows = $row['numrows'];
$maxPage = ceil($numrows/$rowsPerPage);
$self = $_SERVER['PHP_SELF'];
if ($pageNum > 1)
{
$page = $pageNum - 1;
$prev = " <a href=\"$self?page=$page\">[Prec]</a> ";
$first = " <a href=\"$self?page=1\">[INIZIO]</a> ";
}
else
{
$prev = ' [Prec] ';
$first = ' [INIZIO] ';
}
if ($pageNum < $maxPage)
{
$page = $pageNum + 1;
$next = " <a href=\"$self?page=$page\">[Succ]</a> ";
$last = " <a href=\"$self?page=$maxPage\">[FINE]</a> ";
}
else
{
$next = ' [Succ] ';
$last = ' [FINE] ';
}
echo $first . $prev . " Pagina [b]$pageNum[/b] di [b]$maxPage[/b]" . $next . $last;
?>