How can I get the user by clicking Pending , the status changes to Payment ? See:
I'mdoingthefollowing:
PHP
while($csClientes=mysqli_fetch_object($sqlClientes)){$visualizar.="<tr>";
$visualizar .= "<td style='font-weight: bold'><i class=\"fas fa-caret-right\"></i> ".$csClientes->NomeCompleto."</td>";
$visualizar .= "<td style='text-align: center;'>R$ ".number_format($csClientes->ValorTotal,2,',','.')."</td>";
$visualizar .= "<td style='text-align: center'><span class='status'><a href='#!' id='btnAlterar' data-id='".$csClientes->IdFinanceiro."' class='btn btn-danger btn-xs'>Pendente</a></span></td>";
$visualizar .= "</tr>";
}
No JQuery
<script>
$(document).on('click',"#btnAlterar", function(){
var IdFinanceiro = $(this).attr('data-id');
$.post('sistema/alterar-status.php', {key: IdFinanceiro}, function(retorno){
if(retorno == 1){
$(".status").html("<a href='#!' id='btnAlterar' data-id='<?php echo $csClientes->IdFinanceiro; ?>' class='btn btn-success btn-xs'>Pago</a>");
}else{
$(".status").html("<a href='#!' id='btnAlterar' data-id='<?php echo $csClientes->IdFinanceiro; ?>' class='btn btn-danger btn-xs'>Pendente</a>");
}
});
});
</script>
PHP that changes status
$sql = mysqli_query($this->conexao,"UPDATE pagamentos SET StatusPagamento = 'P' WHERE IdPagamento = '".$_POST["key"]."';");
if(mysqli_affected_rows($this->conexao) > 0){
echo '1';
}else{
echo '0';
}
When I click the Fernando Pessoa button, it changes not only his but also everyone's.
Itriedthiswaytoo:
<script>$(document).on('click',"#btnAlterar", function(){
var IdFinanceiro = $(this).attr('data-id');
$.post('sistema/alterar-status.php', {key: IdFinanceiro}, function(retorno){
if(retorno == 1){
$("#statusPago").css('display','block');
$("#statusAberto").css('display','none');
}else{
$("#statusAberto").css('display','block');
$("#statusPago").css('display','none');
}
});
});
</script>
And in HTML
<td style='text-align: center'>
<span id='statusAberto' style='display: block'><a href='#!' id='btnAlterar' data-id="<?php echo $csClientes->IdFinanceiro; ?>" class='btn btn-danger btn-xs'>Pendente</a></span>
<span id='statusPago' style='display: none'><a href='#!' id='btnAlterar' data-id="<?php echo $csClientes->IdFinanceiro; ?>" class='btn btn-success btn-xs'>Pago</a></span>
</td>
But this time it changes the first and not the Fernando Pessoa when I click: