1
I am trying to create a search system using a Request to get the search result.
I am not able to bring the product data related to the title researched.
Whatever the searched word, it always brings me the last item of the product table.
Code for search or search below:
<form action="prod_index_consulta.php" method="get">
<span>Busca Avançada</span>
<input type="image" name="busca" img src="img/search.gif" />
<input type="text" value="" name="buscar"/>
</form>
<script language="javascript">
$(document).ready(function(){
$('.search').click(function(){
var cod = $(this).attr('id');
$.ajax({url:"prod_index_consulta.php?buscar="+cod,success:function(data){
$('#visual').html(data);
}
});
});
});
</script>
Below code to receive product data, searched by title:
<?php
include "conexao.php";
$buscar = $_GET['buscar'];
$sql = "SELECT * FROM pagcabecalho, menu, produto WHERE titulo LIKE :pesquisa";
$resultados = $pdo->prepare($sql);
$resultados->bindParam(':pesquisa', $buscar, PDO::PARAM_STR);
$resultados->execute();
foreach($resultados as $res){
echo'
<div id="prod" style="background-color:'.$res["fundosite_cor"].';width:33%; float:left; padding:10px 0;" class="center_prod_box">
<div align="center" id="titulo" style="width:100%;">
'.$res["titulo"].'
</div>
<div align="center" style="width:100%; height:130px; background-color:'.$res["fundosite_cor"].';">
<div align="center">
<a href="prod_detalhe_5.php?codigo='.$res["codigo"].'">
<img style="width:100%; max-width:100px;" src="img_produtos/'.$res["img01"].'" />
</a>
</div>
</div>
<div align="center" id="preco" style="width:100%;">
<span style="">R$ '.$res["preco"].'</span>
</div>
<div align="center" id="carrinho" style="width:100%;">
<a href="prod_carrinho.php?acao=add&codigo='.$res["codigo"].'">
<img style="width:100%; max-width:20px;" src="img/carrinho.png" title="Por no Carrinho" />
</a>
</div>
</div>
';
}?>
I’m a layman on the subject and I’m trying to learn a little bit in Madrid, but I think the problem lies in this line below the script:
$.ajax({url:"prod_index_consulta.php?buscar="+cod,success:function(data){
Because it gives me the impression that something is missing for him to fetch the product according to the research.
If your friends can help me with that question, I’d be grateful.
Hello Wees Smith, I made the change you recommended, but without success. I decided to do with FORM and it worked in part. It brings me the data searched correctly, but not using the SCRIPT, but the page that is in the FORM ACTION
<form action="prod_index_consulta.php" method="get">
. I edited the Code for research, with this you can show me how to increment or open it in DIV #visual using SCRIPT?– Murilo