I need to do an update to my MySQL database asynchronously.
I have a table with bank results.
<?php
$sqlCategoria = "SELECT * FROM categorias";
$resultCategoria = mysql_query($sqlCategoria);
while($categorias = mysql_fetch_array($resultCategoria)){
?>
No while, I put this script to update.
But it only works the first time.
<script type="text/javascript">
function alterar_div() {
$.ajax({
type: "POST",
url: "processo.php",
data: {
id_item: $('#id_item').val(),
valor: $('#valor').val()
},
success: function(data) {
$('#conteudo').html(data);
}
});
}
</script>
Why is this happening?
The Code as I Did!
<script type="text/javascript">
function alterar_div() {
$.ajax({
type: "POST",
url: "processo.php",
data: {
id_item: $('#id_item').val(),
valor: $('#valor').val()
},
success: function(data) {
$('#conteudo').html(data);
}
});
}
</script>
<?php
$sqlCategoria = "SELECT * FROM categorias";
$resultCategoria = mysql_query($sqlCategoria);
while($categorias = mysql_fetch_array($resultCategoria)){
$sqlItens ="SELECT * FROM itens WHERE it_ctid = '".$categorias['ct_id']."'";
$resultItens = mysql_query($sqlItens);
while($itens = mysql_fetch_array($resultItens)){
$sqlNao = "select rp_valor, rp_id from respostas
left join check_list on (ch_id = rp_chid)
left join itens on (it_id = rp_itid)
where ch_token = '".$token."' and it_id = '".$itens['it_id']."'";
$resultNao = mysql_query($sqlNao);
$valor = mysql_fetch_array($resultNao);
}?>
<input id="id_item" type="hidden" value="<? echo $valor['rp_id']; ?>" />
<input id="valor" type="hidden" value="0" />
<button type="button" onclick="alterar_div()"> <img src="assets/imagens/bt_nao2.png" width="30" height="30" alt=""/></button>
<?php }?>
Process.pho file
<?php
include('includes/mysql.php');
$id = $_POST['id_item'];
$valor = $_POST['valor'];
$sql = mysql_query("UPDATE respostas SET rp_valor = '".$valor."' WHERE rp_id = '".$id."'");
?>