Jump to content
Fórum Script Brasil
  • 0

[Duvida] Paginaçao


GtOkAi

Question

estou precisando inserir paginaçao nesse forum simples:

<?php
 $host="*******"; 
 $username="*******";
 $password="*******";
 $db_name="*******"; 
 $tbl_name="*******";

 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">
 <tr>
 <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>

 </tr>
 </tr>
 <?php
 while($rows=mysql_fetch_array($result)){ 
 ?>
 <tr>
 <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>

 </tr>

 <?php
 }
 mysql_close();
 ?>

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

http://www.phpeasystep.com/phptu/29.html

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'];
echo"
<tr>
<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>
</tr>";

}

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.

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.



  • Forum Statistics

    • Total Topics
      152.1k
    • Total Posts
      651.8k
×
×
  • Create New...