Duplicate repetition

0

I have a problem with the repetition of my result, in fact I can not find a solution. Notice that in the image below we have the order number and the parcels, but this order number always repeats when a new parcel is requested. it does not repeat that it is only 1 time under him the parcels of the own, I tried for another foreach in below the order number but it does not work, can someone help me?

Code:

<?php$Cod=filter_input(INPUT_GET,'cod',FILTER_VALIDATE_INT);if($Cod):$ReadCheck=newRead;$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> 
    
asked by anonymous 20.06.2017 / 02:02

1 answer

0

You can use a variable by passing the order number there validate if the variable (with the value of the previous order number) is the same as the current one 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
    
20.06.2017 / 03:40