Jump to content
Fórum Script Brasil
  • 0

[Duvida] Paginaçao



estou precisando inserir paginaçao nesse forum simples:


 mysql_connect("$host", "$username", "$password")or die("Erro(0)!");
 mysql_select_db("$db_name")or die("Erro(1)");

 <table width="100%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#000000">
 <td width="6%" align="center" bgcolor="#000000"><strong>Nº</strong></td>
 <td width="13%" align="center" bgcolor="#000000"><strong>Data</strong></td>
 <td width="53%" align="center" bgcolor="#000000"><strong>Titúlo</strong></td>
 <td width="15%" align="center" bgcolor="#000000"><strong>Autor</strong></td>
 <td width="15%" align="center" bgcolor="#000000"><strong>Lidas</strong></td>

 <td bgcolor="#000000"><? echo $rows['id']; ?></td>
 <td align="center" bgcolor="#000000"><? echo $rows['datetime']; ?></td>
 <td bgcolor="#000000"><a href="view_topic.php?id=<? echo $rows['id']; ?>"><? echo $rows['topic']; ?> - [<? echo $rows['reply']; ?>]</a><BR></td>
 <td align="center" bgcolor="#000000"><? echo $rows['name']; ?></td>
 <td align="center" bgcolor="#000000"><? echo $rows['view']; ?></td>



já tentei de varias maneiras, todas dando erro, usei este tutorial:


alguém pode ajudar a integrar os 2 scripts? Obrigado.

Edited by GtOkAi
Link to comment
Share on other sites

4 answers to this question

Recommended Posts

  • 0

com esse ai eu consegui fazer funcionar:

$re = mysql_query("SELECT count(*) as total FROM $tbl_name");
$total = mysql_result($re, 0, "total");

$pagina = 0;
if(isset($_GET["pagina"])) {

$pagina = $_GET["pagina"];


$limite = 20;
$paginas = ceil($total / $limite);

$inicio = $pagina * $limite;

$sql = mysql_query("SELECT * FROM $tbl_name LIMIT $inicio, $limite");

$conta = mysql_num_rows($sql);

while($l = mysql_fetch_array($sql)) {
     $id = $l['id'];
     $datetime = $l['datetime'];
     $topic = $l['topic'];
     $reply = $l['reply'];
     $name = $l['name'];
     $view = $l['view'];
<td bgcolor='#000000'>$id</td>
<td align='center' bgcolor='#000000'>$datetime</td>
<td bgcolor='#000000'><a href='view_topic.php?id=$id'> $topic - [$reply]</a><BR></td>
<td align='center' bgcolor='#000000'>$name</td>
<td align='center' bgcolor='#000000'>$view</td>


if($pagina > 0) {
   $menos = $pagina - 1;
   $url = $_SERVER["PHP_SELF"]."?pagina=".$menos;
   echo "<a href=\"$url\">Anterior</a>";
for($i = 1;$i < $paginas; $i++) {
   $url = $_SERVER["PHP_SELF"]."?pagina=".$i;
   echo " | <a href=\"$url\">$i</a>";
if($pagina < $paginas) {
   $mais = $pagina + 1;
   $url = $_SERVER["PHP_SELF"]."?pagina=".$mais;

   echo " | <a href=\"$url\">Próxima</a>";


porem, aparece os topicos em ordem crescente, e alguns fora de ordem.

já tentei colocar ORDER BY id nesses 2:

$sql = mysql_query("SELECT * FROM $tbl_name LIMIT $inicio, $limite ORDER BY id DESC");

$re = mysql_query("SELECT count(*) as total FROM $tbl_name ORDER BY id DESC");

nenhum funciono... como eu faço para colocar em ordem decrescente?

Edited by GtOkAi
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.

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.

  • Forum Statistics

    • Total Topics
    • Total Posts
  • Create New...