1
I am currently using this Code below to search the page with the products related to the requested brand.
echo '<a class="marca" href="prod_index_marca.php?codmarca='.$res['codigo'].'">'.$res['nome_marca'].'</a>';
But I’m trying to create a Request so that this same content opens in a "DIV" without Refresh, so below:
echo '<a class="marca" style="cursor:pointer;">'.$res['nome_marca'].'</a>';
<script language="javascript">
$(document).ready(function(){
$('.marca').click(function(){
$.ajax({url:"prod_index_marca.php?codmarca=<?php $res['codigo'];?>",success:function(data){
$('#visual').html(data);
}});
});
});
And the page "prod_index_marca.php" is starting with the following PHP below, and with all the $res related to the products of the brand selected through its "codmarca":
<?php
include "conexao.php";
$codmarca = $_GET['codmarca'];
$sql = $pdo->prepare("SELECT * FROM produto WHERE codmarca = '$codmarca'");
$sql->execute();
foreach($sql->fetchAll() as $res){
?>
Once done, I verified that the page is being directed to the desired "DIV", but it is not bringing me the data of the products related to codmark requested.
If friends can give me a help to solve, or even indicate where I can research how to create this Request, I would be most grateful.
Thanks in advance for the attention to my problem.
Thanks Smith, that’s what was missing... Nothing better than someone from outside to see our mistakes, THANK YOU even...
– Murilo
Thank you for being able to help @Murilo
– Wees Smith
Smith, I came across another problem. I’m not getting to bring the products referring to the selected brand. Any brand I click, always brings me the same product. Could you see where I’m going wrong? Again THANK YOU...
– Murilo
I will edit my reply with a possible solution
– Wees Smith
edited, check if it worked
– Wees Smith
I do not use "id" and yes "code", I can change to:
var cod = $(this).attr('codigo');
– Murilo
The
id
in question is an attribute of the tag only, which will count the value of the code– Wees Smith
Let’s go continue this discussion in chat.
– Murilo