Duplicate

Asked

Viewed 59 times

0

I’m having a problem repeating my result, actually I’m not able to find a solution realize that in this image below we have the order number and parcels, but this order number always repeats when to a new installment, I want him not to repeat that stay only 1 time below him the parcels of own, I tried for another foreach in under the order number but I don’t function, someone can help me?

inserir a descrição da imagem aqui

Code:

<?php
    $Cod = filter_input(INPUT_GET, 'cod', FILTER_VALIDATE_INT);
    if ($Cod):
        $ReadCheck = new Read;
        $Hoje = date('Y-m-d');
        $N = "N";
        $ReadCheck->ExeRead("c022vdpr", "WHERE cod_cliente = :cod AND vct_parcela < :vct AND quitacao = :quit", "cod={$Cod}&vct={$Hoje}&quit={$N}");
        if ($ReadCheck->getResult()):
            $read = new Read;
            $read->ExeRead("c002clie", "WHERE codigo = :cod", "cod={$Cod}");
            if ($read->getResult()):
                $Nome = $read->getResult()[0]['razao'];
            endif;
            echo " <table style=\"width: 100%; text-align: left\" >
                    <thead><th style=\"width: 50%;\">Nome</th><td colspan=\"2\" style=\"width: 50%;\">{$Nome}</td></thead>";

            foreach ($ReadCheck->getResult() as $Pedidos):
                extract($Pedidos);
                ?>

                <thead><th>Pedido</th><td><?php echo $nro_pedido ?></td></thead>
                <?php
                $ReadParce = new Read;
                $ReadParce->ExeRead("c022vdpr", "WHERE nro_pedido = :ped", "ped={$nro_pedido}");
                ?>
                <thead><th>Vencimento</th><th>Valor</th><th>N° Parcela</th></thead>
<tr><td><?php echo date('d/m/Y', strtotime($vct_parcela)); ?></td><td>R$ <?php echo $vlr_parcela ?></td><td><?php echo $nro_parcela ?></td></tr>
                <tr><td colspan="3" style="background-color: #ccc; padding: 3px;"></td></tr>
                <?php
            endforeach;
        endif;
    endif;
    ?>
    </table> 
  • Already tried to put only the line referring to the order number outside the foreach?

  • So the worst is that I have to put in the foreach if not, the repetition will not work, is that this all in a table

  • http://i68.tinypic.com/qn304l.jpg

  • But the goal is not to fail to repeat the order number?

  • Yes, but in the bank is the number of installments and the order number type: 1 line = order number 1234, plot number 1; 2 line = order number 1234, plot number 2;

  • The past link is broken. And why should the first installment bring the order number different from the others? Or are different orders even?

  • then all parcels brings the order number so it repeats itself, but what I did, I put a distinct request in my first select and made the foreach, bringing only the order numbers without duplication, only in the second select I picked up the plots putting in a second foreach and it worked!

  • http://imgur.com/V6mOIWc

Show 3 more comments

1 answer

0

You can use a variable by passing the order number then validate if the variable (with the value of the previous order number) is equal to the current of the loop (at the end of the loop save the order number in the variable, to make the next comparison and so on):

$guardapedido = '';

foreach...

<?php if ($guardapedido != $nro_pedido) { ?>
    <thead><th>Pedido</th><td><?php echo $nro_pedido; ?></td></thead>
<?php } ?>

<?php $guardapedido = $nro_pedido; ?>

...endforeach

Browser other questions tagged

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