I made a part of my paging system but it always shows the maximum number of products in my bank and in the search I specified the name.
Type I do the search for Leonardo in my bank has Leonardo registered and 8 more people there he brings me the Leonardo as first and continues showing with nothing I read the pagination with the numbers how can I sort this to search for what the guy type in the search form?
My code is this:
<?php
require_once("classe/conexao.class.php");
$c = new Conexao();
$c->conecta();
// inicia paginacao
$totalProduto = 1;
$pagina = (@isset($_GET['pagina'])) ? (int)$_GET['pagina']: 1;
$inicio = ($totalProduto * $pagina) - $totalProduto;
$busca = $_GET['q'];
$sql = mysql_query("SELECT * FROM produtos WHERE nome LIKE '%$busca%' OR categoria LIKE '%$busca%' ORDER BY id_produto LIMIT $inicio, $totalProduto");
if(empty($_GET['q'])){
echo"<script>alert('Nenhum Resultado Encontrado'), window.open('index.php','_self')</script>";
exit();
}
while($registro = mysql_fetch_array($sql)){
$nome = $registro['nome'];
$categoria = $registro['categoria'];
$descricao = $registro['descricao'];
$preco = $registro['preco'];
$img = $registro['img'];
$id = $registro['id_produto'];
$_SESSION['id'] = $id;
print"
<div class=\"col-sm-4\">
<div class=\"product-image-wrapper\">
<div class=\"single-products\">
<div class=\"productinfo text-center\">
<img src=\"images/shop/$img\" alt=\"$nome\" width=\"694\" height=\"300\" />
<h2>R$ $preco</h2>
<p>$nome</p>
<a href=\"detalhe.php?cod=$id\" class=\"btn btn-default add-to-cart\"><i class=\"fa fa-shopping-cart\"></i>Detalhes</a>
</div>
</div>
</div>
</div>";
}//fim while
$sqlTotal = "SELECT id_produto FROM produtos";
$qrTotal = mysql_query($sqlTotal) or die (mysql_error());
$numTotal = mysql_num_rows($qrTotal);
$totalPagina = ceil($numTotal/$totalProduto);
?>
<div class="col-md-12 text-center">
<?php
echo"
<ul class=\"pagination\">
<li class=\"active\"><a href=\"?pagina=1&q=$busca\">Primeira Pagina</a></li>
</ul>
";
for($i = 1; $i <= $totalPagina; $i++){
if($i == $pagina)
echo "
<ul class=\"pagination\">
<li class=\"active\"><a hreaf=".$i.">$i</a></li>
</ul>";
else
echo"
<ul class=\"pagination\">
<li><a href=\"?pagina=$i&q=$busca\">$i</a></li>
</ul>
";
};
mysql_close();
?>