Pagination of results with search in two fields

-1
Hello, I'm looking for help because I'm having trouble creating a result page, I made a page that contains two search fields, "what to look for" and "where to search", it works and filters correct, but I'm not able to do paging to limit the search results, where am I going to be missing the following code?

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


   $consulta1 ="SELECT * FROM registro_clientes";
   $qrTotal  =mysqli_query($conexao,$consulta1) or die(mysqli_error());
   $numTotal =mysqli_num_rows($qrTotal);
   $quantidade = 2;

   $totalPagina=ceil($numTotal/$quantidade);

   $inicio = ($quantidade * $pagina) - $quantidade;


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

                 if(isset($_GET['buscar'])&& isset($_GET['onde'])){

                   $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))
    
asked by anonymous 01.08.2015 / 13:46

1 answer

0
  • You'd better use SELECT COUNT(*) FROM registro_clientes; to find out how many records there are. The query is much smaller and more peformatica.
  • I did not quite understand the account you wanted to use, but this should work better. $inicio = ($pagina - 1) * $numTotal
01.08.2015 / 14:34