I have this script where I created it to appear all the records contained in the database where all products with the same category appear (show name and value)
and the client clicks the desired quantity and the value appears when clicking the result appears and then sends it to the database
But when I click on the quantity of the first product the multiplication is done so that the result appears in all the other tables and when I click on the quantity of the second table the multiplication is not done and still maintains the result of the first product this happens with the third and fourth
*Howtomakeeachonemultiplyandshowitsresult.*
<?phppublicfunctionlistarProduto($sql){$total=$this->totalRegistros($sql);for($j=0;$j<$total_prod;$j++){$this->verTudo($sql,$j);$sqlRegistro="SELECT * FROM produto WHERE id='$id'";
$result = mysql_query($sqlRegistro);
$idProduto = mysql_result($result, 0, "idProduto");
$idNomeProduto = mysql_result($result, 0, "idNomeProduto");
$valor = mysql_result($result, 0, "valor");
$action = "op/opcadastro.php";
echo "
<script>
$(document).ready(function(){
$('#valor, #qtde').click(function(){
var valor = $('input[name=valor]').val();
var qtde = $('#qtde').val();
if(valor == '') valor = 0;
if(qtde == '') qtde = 0;
var result = ((valor) * (qtde)).toFixed(2);
$('.resultado').html(result.replace('.',',').replace(/(\d)(?=(\d{3})+\,)/g, '$1.'));
});
});
</script>
<table border='1' cellpadding='0' cellspacing='0' id='tabela'>
<tr><td>Nome do Produto</td>
<td>$idNome</td>
</tr>
<tr><td>Quantidade</td>
<td><input type='number' id='qtde' name='qtde'></td>
</tr>
<tr><td>Valor</td>
<td><input type='hidden' id='qtde' name='qtde'> $valor</td>
</tr>
<tr><td>Resultado</td>
<td><span class='resultado'></span></td>
</tr>
<tr><td colspan='2'>
<form action='$action' method='post' enctype='multipart/form-data'>
<input type='hidden' name='idProduto' value='$idProduto'/>
<input type='hidden' name='qtde' value='$qtde'/>
<input type='hidden' name='valor' value='$valor'/>
<input type='hidden' name=acao value='INSERIR' />
<input type='submit' value='Adicionar à Lista'>
</form></td></tr>
</table>";
}
}
?>