Change buttons to appear as quantities are dropped

Asked

Viewed 36 times

4

I have a table where I store the customer payments and between the columns are these two:

inserir a descrição da imagem aqui

And the listing is that way:

inserir a descrição da imagem aqui

<?php 
    for($p = 1; $p <= $visualizarR[1]->QtdParcelas; $p++){
       $botao = ($visualizarR[1]->QtdParcelasPagas == 0)?'<button class="btn btn-danger btn-mini" onclick="window.location.href=\'confirmar-pagamento/?'.$peVisualizar->IdCodPagamento.'\';">Aberto</button></div>':'<button class="btn btn-success btn-mini">Pago</button></div>';
        echo '<div style="padding: 10px">'.$p.'º Parcela: '.$botao;
    } 
?>  

When the user clicks on the button Open, he includes in the field QtdParcelasPagas value 1 and count against existing values. So far so good, but I need to change the button Open for Paid as it is slaughtering the plots, but without reducing the number of plots listed, changing only the value of the button. How can I do this?

  • 1

    makes an if inside is to check if the installment has already been paid, if it has been paid you will print a different button

  • Hello Wees. I’ve tried using a ternary operator but it didn’t work.

  • 1

    Hello Fox! Which variable identifies when the installment has been paid or is open? It is with it that you should work to put one thing or another.

  • Hello Sam. I made a change to my post using the variable $visualizarR[1]->QtdParcelasPagas of the installment paid using the button.

  • 1

    I got it. Just one question: let’s say there are 4 installments and only 1 pays, so this 1 must be the first, right? can’t it be the second or the third or the fourth? That’s because the variable $visualizarR[1]->QtdParcelasPagas gives only the amount of installments paid, and which (or which) was paid.

  • 1

    vc uses some identifier for the plots?

Show 1 more comment

1 answer

2


Whereas the instalments paid are in sequence from the first to the last, just change your ternary checking whether the variable $p of the loop for is greater than the value in $visualizarR[1]->QtdParcelasPagas:

for($p = 1; $p <= $visualizarR[1]->QtdParcelas; $p++){
   $botao = $p > $visualizarR[1]->QtdParcelasPagas ?
      '<button class="btn btn-danger btn-mini" onclick="window.location.href=\'confirmar-pagamento/?'.$peVisualizar->IdCodPagamento.'\';">Aberto</button></div>'
      : '<button class="btn btn-success btn-mini">Pago</button></div>';
   echo '<div style="padding: 10px">'.$p.'º Parcela: '.$botao;
} 

Assuming there are 4 installments and 3 were paid, the result will be:

inserir a descrição da imagem aqui

  • Perfect Sam!! I really changed the ternary and it worked properly. Thank you so much again!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.