mithrandix Posted May 4, 2011 Share Posted May 4, 2011 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>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/235487-php-mysql-pagination/ Share on other sites More sharing options...
mithrandix Posted May 4, 2011 Author Share Posted May 4, 2011 Can I get any help pls ? this is rly imp :S I've try everything and nothing worked :S Quote Link to comment https://forums.phpfreaks.com/topic/235487-php-mysql-pagination/#findComment-1210308 Share on other sites More sharing options...
vicodin Posted May 4, 2011 Share Posted May 4, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/235487-php-mysql-pagination/#findComment-1210388 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.