ciao a tutti,
alla fine ho optato per questo script che per la paginazione lo trovo ottimo. Unico problema ora e che se gli arriva una variabile da una pagina post la prima paginazione funziona mentre passando alla seconda pagina perde la variabile passata... non riesco in nessun modo a passargli la variabile anche nelle pagine successive.
Codice PHP:
include('connessione.php');
$provincia= $_POST['provincia'];
// how many rows to show per page
$rowsPerPage = 5;
// by default we show first page
$pageNum = 1;
// if $_GET['page'] defined, use it as page number
if(isset($_GET['page'])){
$pageNum = $_GET['page'];
}
// counting the offset
$offset = ($pageNum - 1) * $rowsPerPage;
$query = "SELECT * FROM immobili WHERE provincia='$provincia' LIMIT $offset, $rowsPerPage";
$result = mysql_query($query) or die('Error, query failed');
//echo "<div id='' class='h9'>Trovati nella ricerca effettuata $numero_record_totali risultati.</div>";
if (!$query) {
echo "Fallimento nell'esecuzione della query ($sql) dal DB: " . mysql_error();
}
if (mysql_numrows(!$query)) {
echo "Nessun immobile trovato nel Database!";
}
// print the random numbers
while($row = mysql_fetch_array($result)){
$provincia= utf8_encode($row['provincia']);
echo "$provincia";
}
// how many rows we have in database
$query = "SELECT COUNT(*) AS numrows FROM immobili WHERE provincia='$provincia'";
$result = mysql_query($query) or die('Error, query failed');
$row = mysql_fetch_array($result, MYSQL_ASSOC);
$numrows = $row['numrows'];
// how many pages we have when using paging?
$maxPage = ceil($numrows/$rowsPerPage);
// print the link to access each page
$self = $_SERVER['PHP_SELF'];
$nav = '';
for($page = 1; $page <= $maxPage; $page++){
if ($page == $pageNum){
$nav .= " $page "; // no need to create a link to current page
}else{
$nav .= " <a href=\"$self?page=$page\">$page</a> ";
}
}
// creating previous and next link
// plus the link to go straight to
// the first and last page
if ($pageNum > 1){
$page = $pageNum - 1;
$prev = " <a href=\"$self?page=$page\">[Prev]</a> ";
$first = " <a href=\"$self?page=1\">[First Page]</a> ";
}else{
$prev = ''; // we're on page one, don't print previous link
$first = ''; // nor the first page link
}
if ($pageNum < $maxPage){
$page = $pageNum + 1;
$next = " <a href=\"$self?page=$page\">[Next]</a> ";
$last = " <a href=\"$self?page=$maxPage\">[Last Page]</a> ";
}else{
$next = ''; // we're on the last page, don't print next link
$last = ''; // nor the last page link
}
// print the navigation link
echo $first . $prev . $nav . $next . $last;
// and close the database connection