I have a problem of pagination of turns out you of one query of search on a DB MySQL. With this code I succeed to visualize the first 5 records out to you in one page but when go in the successive pages it makes to see the first 5 records me of mine database. This is the code:

<?php
$db_host="....";
$db_user="....";
$db_password="...";
$db_database="...";
$c or die ("Errore nella connessione al Mysql:" . mysql_error());
mysql_select_db($db_database,$connessione) or die ("Errore nella selezione del db:" . mysql_error());
 
$numero_record = 5;
if(!isset($HTTP_GET_VARS["inizio"])){
    $inizio = 0;
}else{
    $inizio = $HTTP_GET_VARS["inizio"];
} 
$query_limit="SELECT AnnoRipresa, Id, FROM table_name WHERE AnnoRipresa LIKE '%$_POST[AnnoRipresa]%'
order by Id limit $inizio, $numero_record" or die ("Errore :" . mysql_error());;
 
$query = mysql_query($query_limit);
 
$select = "SELECT AnnoRipresa, Id,  FROM table_name WHERE AnnoRipresa LIKE '%$_POST[AnnoRipresa]%'";
 
$query2 = mysql_query($select);
 
$numero_record_totali = mysql_numrows($query2); 
 
$numero_pagine = ceil($numero_record_totali/$numero_record); 
 
$pagina_corrente = ceil(($inizio/$numero_record) + 1);
while($riga=mysql_fetch_array($query))
{?>
<tr>
<td colspan="2">
<?php
echo <tr>
<td height="22" width="20%"><h4><b>Anno Ripresa</b></td>
echo "<td>" . $riga['Id'] . "</td>";
echo "</tr>";
}
if($numero_pagine > 1){
     for($pagina = 1; $pagina <= $numero_pagine; $pagina++){
          if($pagina == $pagina_corrente){ ?>
              <b><?=$pagina?></b>
         <?php  }else{
 ?>
<a href="fotografie_aeree_verticali.php?inizio=<?=(($pagina - 1) * $numero_record)?>"><?=$pagina?></a>
          <?php
}
}
}
?>

have you tried the PEAR:Pager package? It is really easy to use and is debugged for you. There are also plenty of other packages around, try phpclasses.org as well.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.