0
I need to update 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>
'Cause this is 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 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."'");
?>
You understand exactly what this script ago?
– Woss
Sorry, I had put the script wrong. But also I do not understand much not, if you can help me! I do not know if you understood what I need, today I update my bank via GET but I can not reload the page to make this update.
– Ale Bresio
You can put the full code?
– Woss
I updated! I was doing it this way
<a href="gravar/gravar_respostas.php?id=<? echo $itens['it_id']?>&valor=0&ch_id=<? echo $checklist['ch_id'];?>&token=<? echo $token;?>&id_lj=<? echo $id;?>&rp_id=<? echo $valor['rp_id']; ?>">
And so it goes!– Ale Bresio
Hello @Andersoncarloswoss I managed to help me in this? Thanks
– Ale Bresio