更改foreach

时间:2016-07-14 05:18:31

标签: php twitter-bootstrap codeigniter button foreach

我无法改变按钮的颜色。 只显示绿色。看图像。 我希望每个状态都有一种颜色。不同颜色的按钮 我如何在foreach中改变?

Look at the image

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

                        if (!isset($linha->valor_pagamento["PAGO"])):
                        printf('<td><button type="button" class="btn btn-success btn-xs">%s</button></td>', $linha->status_pagamento);

                        elseif (!isset($linha->valor_pagamento["PENDENTE"])):
                            printf('<td><button type="button" class="btn btn-warning btn-xs">%s</button></td>', $linha->status_pagamento);

                        elseif (!isset($linha->valor_pagamento['NO PAGO'])):
                            printf('<td><button type="button" class="btn btn-danger btn-xs">%s</button></td>', $linha->status_pagamento);
                        endif;
                        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;
                    ?>

1 个答案:

答案 0 :(得分:0)

  

试试这个

<?php
                $query = $this->sindico->get_listfinanceiro()->result();
                $btn_color_class ="";
                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);

                    if (!isset($linha->valor_pagamento["PAGO"])):
                    $btn_color_class = "btn-success";
                    printf('<td><button type="button" class="btn '.$btn_color_class.' btn-xs">%s</button></td>', $linha->status_pagamento);

                    if (!isset($linha->valor_pagamento["PENDENTE"])):
                        $btn_color_class = "btn-warning";
                        printf('<td><button type="button" class="btn '.$btn_color_class.' btn-xs">%s</button></td>', $linha->status_pagamento);

                    if (!isset($linha->valor_pagamento['NO PAGO'])):
                    $btn_color_class = "btn-danger";
                        printf('<td><button type="button" class="btn '.$btn_color_class.' btn-xs">%s</button></td>', $linha->status_pagamento);
                    endif;
                    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;
                ?>