I want to change the color of the button according to the value of the variable

1

I created an if / elseif condition inside the foreache, to change the color of the payment status button. I have three status and three colors for home status. Only he's not picking up the colors. I think the problem is at the moment of clarifying the values for the variable. I'll send a print of my screen.

<?php$query=$this->sindico->get_listfinanceiro()->result();foreach($queryas$linha):echo'<tr>';printf('<td>%s/%s</td>',($linha->numero_apart)?:'/',($linha->nome_usu));printf('<td>%s</td>',$linha->data_pagamento);printf('<td>%s</td>',"Bs:".$linha->valor_pagamento);
                        $class = "" ;
                        if (!isset($linha->valor_pagamento["PAGO"])){
                            $class =  'btn-sucesso' ;}

                        elseif (!isset($linha->valor_pagamento["PENDENTE"])){
                            $class =  'btn-warning' ;}

                        elseif (!isset($linha->valor_pagamento['NO PAGO'])){
                            $class =  'btn-danger' ;}
                        printf('<td><button type="button" class="btn '.$class.' btn-xs">%s</button></td>', $linha->status_pagamento);
                        printf('<td class="text-center">%s</td>', '<div class="btn-group btn-xs"><button data-toggle="dropdown" class="btn btn-xs dropdown-toggle"  data-original-title="" title="">Action<span class="caret"></span></button><ul class="dropdown-menu pull-right"><li><a href="editar/'.$linha->id_finan.'">Edit</a></li><li><a href="excluir/'.$linha->id_finan.'">Delete</a></li>' );

                        echo '</tr>';
                    endforeach;
                    ?>
    
asked by anonymous 15.07.2016 / 03:38

3 answers

0

Change% of% by% with%. If !isset was initialized isset !

    
15.07.2016 / 05:31
0

In general, if you change !isset to isset it will work ...

But, just in case, make a debug seeing if you are entering if , put a exit('Aqui') inside if to make sure you are entering ...

    
19.07.2016 / 02:08
0

You've already tried switching:

  • btn-success by btn-success
  • ! isset by isset
  • and for danger it could just be an else

    <?php
       $query = $this->sindico->get_listfinanceiro()->result();
       foreach ($query as $linha):
         echo '<tr>';
           printf('<td>%s / %s</td>', ($linha->numero_apart) ? :'/', ($linha->nome_usu));
           printf('<td>%s</td>', $linha->data_pagamento);
           printf('<td>%s</td>', "Bs:".$linha->valor_pagamento);
           $class = "" ;
           if (isset($linha->valor_pagamento['PAGO'])){
              $class =  'btn-success' ;
           }
    
           elseif (isset($linha->valor_pagamento['PENDENTE'])){
              $class =  'btn-warning' ;
           } else {
              $class =  'btn-danger' ;
           }
    
           printf('<td><button type="button" class="btn '.$class.' btn-xs">%s</button></td>', $linha->status_pagamento);
           printf('<td class="text-center">%s</td>', '<div class="btn-group btn-xs"><button data-toggle="dropdown" class="btn btn-xs dropdown-toggle"  data-original-title="" title="">Action<span class="caret"></span></button><ul class="dropdown-menu pull-right"><li><a href="editar/'.$linha->id_finan.'">Edit</a></li><li><a href="excluir/'.$linha->id_finan.'">Delete</a></li>' );
    
         echo '</tr>';
       endforeach;
    ?>
    
09.08.2016 / 23:51