Pagination PHP and MySQL

1

I created a search page with two search fields, it is working and everything is ok, so when I search I would like to page, and I am doing something wrong.

My code.

<?php

  $conexao =mysqli_connect($host,$user,$pass,$bank);
  $pagina = (isset($_GET['pagina'])) ? (int)$_GET['pagina'] : 1 ;


  $consulta1 ="SELECT * FROM registro_clientes";
  $qrTotal  =mysqli_query($conexao,$consulta1) or die(mysqli_error());
  $numTotal =mysqli_num_rows($qrTotal);
  $quantidade = 2;
  $inicio = ($pagina - 1) * $quantidade;
  $totalPagina=ceil($numTotal/$quantidade);




   if(mysqli_connect_errno($conexao)){
       echo "erro conect hen";
       }else{

             {

               $nome = $_GET['buscar'];
               $bairro = $_GET['onde'];
           $consulta = "SELECT * FROM registro_clientes 
           WHERE nome_cliente LIKE '%$nome%' AND bairro LIKE '%$bairro%' 
           ORDER BY preferencial ASC 
           LIMIT $inicio, $quantidade ";
           $executar = mysqli_query($conexao,$consulta);

           $total = mysqli_num_rows($executar);

        echo  "Encontrado     ".$total. "     resultado(s):";
        echo "<br>";
        echo "<hr>";                        

         while ($ln=mysqli_fetch_array($executar)){              
        echo "<br>";
        echo "" .$ln['nome_cliente'] ."<br>";
        echo "" .$ln['nome_comercio'] ."<br>";
        echo "" .$ln['tipo_com_serv'] ."<br>";
        echo "" .$ln['bairro'] ."<br>";
        echo "" .$ln['endereco'] ."<br>";
        echo "" .$ln['fone1'] ."<br>";
        echo "" .$ln['email'] ."<br>";
        echo "" .$ln['site'] ."<br>";
        echo"" .$ln['nome_imagem'] ."<br>";                     
        echo "<br>";
        echo "<hr>";                        
                    }                               
                }
          }  


       echo '<a href="?pagina=1">  primeira pag  </a> - ';

       for($i = 1; $i <= $totalPagina; $i++){

           if($i == $pagina)
            echo $i;
            else
            echo"<a href='resultados.php?pagina=$i'>". $i. "</a>";  

           }

       echo" - <a href=\"?pagina=$totalPagina\">  ultima pag  </a> ";





           ?>
    
asked by anonymous 02.08.2015 / 23:18

0 answers