Jump to content

PHP mysql Pagination


mithrandix

Recommended Posts

Hello, i'm new around here.

 

 

I have a query, and when I click on the Next button to show my other results.

 

 

When I 1º do the display, it shows 6 results that are correct and after I do next, no error are displayed but the displayed data go from 6 to 7 :S

 

 

Can I get a help on this plz =S rly impp..

 

<?php 

$host = "localhost"; 
$username = "root"; 
$senha= ""; 
$banco_dados = "*******"; 
$tabela = "artigos"; 
$numero_links = "4"; 
$total_reg = "2"; 

if(isset($_POST["Familia"])){
   $search = mysql_escape_string($_POST["Familia"]);
} else {
   $search = "";
}

if(!$pagina) { 
$pc = "1"; 
} else { 
$pc = $pagina; 
} 

$intervalo = $numero_links; 
$inicio = $pc-1; 
$inicio = $inicio*$total_reg; 
mysql_connect($host,$username,$senha); 
mysql_select_db($banco_dados); 


$sql = mysql_query("SELECT * FROM $tabela where Familia LIKE '%".$search."%' "); 
$tr = mysql_num_rows($sql); 
$sql2 = mysql_query("SELECT * FROM $tabela where Familia LIKE '%".$search."%' LIMIT $inicio,$total_reg"); 
$tp = ceil($tr/$total_reg); 

echo "<font size='1' face='Verdana'>"; 
echo "Página $pc de $tp<br> Total de registros: $tr<br><br>"; 
echo "</font>"; 
echo "<hr>"; 
while($dados=mysql_fetch_array($sql2)) { 
$id = $dados["Nome"]; 
$nome = $dados["CodigoBarras"]; 
echo "$id - $nome<br>\n"; 
} 

$aux = $tp/$intervalo; 
$aux1 = $pc/$intervalo; 
$pi = $aux1 * $intervalo; 
if ($pi == "0") { 
$pi = "1"; 
} 
$pf = $pi + $intervalo -1; 
$anterior = $pi-$intervalo; 
if($pc<=$intervalo) { 
$anterior = 1; 
} 
$aux2 = $pi + 1; 
if($pi>1) { 
$aux = $pi - 1; 
$aux2 = $pi + 1; 
echo "<hr>"; 
    echo " <<<a href='{$_SERVER['PHP_SELF']}?pagina=1'>Primeiro</a> "; 
      echo "<<a href='paginacaotest.php?pagina=$aux'><b> Anterior </b></a> "; 
} 
else 
{ 
     echo "<font size='1' face='Verdana'>"; 
     echo "<< Primeiro  "; 
     echo "</font>"; 
     echo "<font size='1' face='Verdana'>"; 
     echo "<< Anterior   "; 
     echo "</font>"; 
} 

for ($pi;$pi<$pf;$pi++) 
{ 
      if($pi<=$tp) { 
          if($pc==$pi) { 
               echo "<strong><font size='1' face='Verdana'>"; 
             echo "<b>[" . $pi . "]</b> "; 
             echo "</font></strong>"; 
          } else { 
             echo "<a href='paginacaotest.php?pagina=" . $pi . "'>" . $pi . "</a> "; 
          } 
      } 
} 

if($pc != $tp){ 
         echo "<strong><font size='1' face='Verdana'>"; 
      echo "<a href='paginacaotest.php?pagina=$aux2'><b>    Próximo</b></a> >"; 
      echo " <a href='{$_SERVER['PHP_SELF']}?pagina=$tp'>Ultimo</a> "; 
      echo "</font></strong>"; 
    } 
    else 
    { 
     echo "<font size='1' face='Verdana'>"; 
     echo "    Próximo >>"; 
     echo "</font>"; 
     echo "<font size='1' face='Verdana'>"; 
     echo "    Ultimo >>"; 
     echo "</font>"; 
    } 
?>

Link to comment
Share on other sites

I would love to help you but I am having trouble understanding what your problem is. Also your code is not very readable. Can you please name your variables to something relevant so everyone knows exactly what that variable is... and also please tab your code correctly so its more readable.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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

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.