Jump to content

[Resolvido] Lógica - Paginação


t0ze

Recommended Posts

Boa noite, como podem ver neste exemplo aqui http://t0ze.dynip.sapo.pt/static/ tenho uma tabela com paginação, (fazendo uso de uma classe pagination).

Só que como podem ver todas as paginas são apresentadas. Já andei aqui a martelar ciclos for, mas nunca acerto... o objectivo seria:

Sendo por exemplo a pagina actual = 10 mostrar apenas

Previous... 7 8 9 10 11 12 13 ... Next

$page = !empty($_GET['page']) ? (int)$_GET['page']: 1;
    //records per page
    $per_page = 10;
$total_count = country_count_all();
    $pagination = new pagination($page, $per_page, $total_count);
    $offset = $pagination->offset();
    $total = $pagination->total_pages();
$query ="SELECT country.*
    FROM country
    LIMIT 10
    OFFSET $offset";
$table = "";
$result_set = mysql_query($query);
confirm_query($result_set);

$table = "<table id=\"myTable\" class=\"tablesorter\"style='width:100%; border-spacing:0;'>
	  <thead>
	  <tr>
	    <th>Nome</th>
	    <th>Nome Local</th>
	  </tr>
	  </thead>";

while($country =  mysql_fetch_array($result_set)){
   $table = $table."<tr><td>".$country['Name']."</a></td>
  <td >". $country['LocalName']."</td>
 </tr>";
}
echo $table;
if ($pagination->total_pages()>1) {
 if ($pagination->has_previous_page()) {
   $previouspage =   $pagination->previous_page();
   echo " <a href='index.php?page=$previouspage'> Previous </a> ";
 }

 for ($i=1; $i <= $total; $i++) {
   if ($i == $page) {
  echo " <a href=\"index.php?page={$i}\"> <b><u>{$i}</u></b> </a>";
   }else{
  echo " <a href=\"index.php?page={$i}\"> {$i} </a>";
   }
 }

 if ($pagination->has_next_page()) {
   $nextpage = $pagination->next_page();
   echo " <a href='index.php?page=$nextpage'> Next </a> ";
 }
}
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.