Jump to content
t0ze

[Resolvido] Lógica - Paginação

Recommended Posts

t0ze

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> ";
 }
}

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • 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.