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

Asked

Viewed 572 times

1

I created an if/elseif condition inside the foreache, to change the color of the pay status button. I have three status and are three colors for home status. Only he’s not getting the colors. I think the problem is time to select the values for the variable. I’ll send a print of my screen.

Minha tela

 <?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-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;
                    ?>
  • If you are using bootstrap then the correct class is btn-Success. Check to see if you’re really getting into if ?

3 answers

0

In general if you change !isset for isset will work...

But, just for a little bit, do a debug to see if you’re getting into if, dinghy one exit('Aqui') within the ifto make sure you’re in...

0

Ever tried to trade:

  • 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;
    ?>
    

0


Change !isset for isset. If $linha was initialized echo "sucess"!

Browser other questions tagged

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