Jump to content
Fórum Script Brasil
  • 0

Como Fazer Paginação em PHP


diego_kleins
 Share

Question

1 answer to this question

Recommended Posts

  • 0

Exemplo:

 

<?php 
$numero_por_pagina=10;
mysql_connect('localhost','root','');
mysql_select_db('suadatabase');
if (isset($_GET["page"])) { $page  = $_GET["page"]; } else { $page=1; }; 
$comecar = ($page-1) * $numero_por_pagina; 
$sql = "SELECT * FROM estudantes LIMIT $comecar, $numero_por_pagina"; 
$rs_result = mysql_query ($sql); //Executa a query
?> 
<table>
<tr><td>Nome</td><td>Telefone</td></tr>
<?php 
while ($row = mysql_fetch_assoc($rs_result)) { 
?> 
            <tr>
            <td><?php echo $row['Nome']; ?></td>
            <td><?php echo $row['Telefone']; ?></td>            
            </tr>
<?php 
}; 
?> 
</table>
<?php 
$sql = "SELECT * FROM estudantes"; 
$rs_result = mysql_query($sql); //Executa a query
$total_records = mysql_num_rows($rs_result);  //conta o número
$total_pages = ceil($total_records / $num_rec_per_page); 

echo "<a href='pagination.php?page=1'>".'|<'."</a> "; // Vai para primeira página 

for ($i=1; $i<=$total_pages; $i++) { 
            echo "<a href='pagination.php?page=".$i."'>".$i."</a> "; 
}; 
echo "<a href='pagination.php?page=$total_pages'>".'>|'."</a> "; // Vai para última página
?>

 

Link to comment
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
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  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.

 Share



  • Forum Statistics

    • Total Topics
      150.1k
    • Total Posts
      647k
×
×
  • Create New...