Visualizzazione dei risultati da 1 a 4 su 4
  1. #1

    Subtotali in tabella con esecuzione query

    ciao!

    sto mettendo i dati in una tabella, e vorrei aggiungere una riga quando cambia il valore di un record: $var['uscita_pacc'].
    al momento ha solo due valori, 1 e 5.
    al momento in cui cambia devo aggiungere una riga.


    ho fatto così:
    Codice PHP:
                    <tbody>
                        <?php
                        
    foreach ($queryPacc as $var):
                            
    $upNow $var['uscita_pacc'];

                            if (isset(
    $upOld) && $upNow != $upOld):
                                
    ?>
                                <tr>
                                    <th>TOT <?php echo $upOld?></th>
                                    <th></th>
                                    <th></th>
                                    <th></th>
                                    <th></th>
                                </tr>
                            <?php endif; ?>

                            <tr>                         
                                 <td></td>
                                 <td></td>
                                 <td></td>
                                 <td></td>
                                 <td></td>
                            </tr>
                            <?php
                            $upOld 
    $var['uscita_pacc'];
                        endforeach;
                        
    ?>

                        <tr>
                            <th>TOTALE</th>
                            <th></th>
                            <th></th>
                            <th></th>
                            <th></th>
                        </tr>
                    </tbody>

    il problema sta nel fatto che quando si passa da 1 a 5, viene aggiunta la riga.
    non viene, ovviamente, aggiunta alla fine.
    in sostanza mi manca il subtotale di 5.
    come posso fare??

  2. #2
    Utente di HTML.it L'avatar di las
    Registrato dal
    Apr 2002
    Messaggi
    1,221
    Codice PHP:
    <tbody>
                        <?php
                        
    foreach ($queryPacc as $var):
                            
    $upNow $var['uscita_pacc'];

                            if (isset(
    $upOld) && $upNow != $upOld):
                                
    ?>
                                <tr>
                                    <th>TOT <?php echo $upOld?></th>
                                    <th></th>
                                    <th></th>
                                    <th></th>
                                    <th></th>
                                </tr>
                            <?php endif; ?>

                            <tr>                         
                                 <td></td>
                                 <td></td>
                                 <td></td>
                                 <td></td>
                                 <td></td>
                            </tr>
                            <?php
                            $upOld 
    $var['uscita_pacc'];
                        endforeach;
                        
    ?>

                                <tr>
                                    <th>TOT <?php echo $upOld?></th>
                                    <th></th>
                                    <th></th>
                                    <th></th>
                                    <th></th>
                                </tr>                    
                                <tr>
                            <th>TOTALE</th>
                            <th></th>
                            <th></th>
                            <th></th>
                            <th></th>
                        </tr>
                    </tbody>
    Il calcolatore è straordinariamente veloce, accurato e stupido.
    L'uomo è incredibilmente lento, impreciso e creativo.
    L'insieme dei due costituisce una forza incalcolabile.
    (Albert Einstein)

  3. #3
    me lo dico da solo:

    domani sistemo.....grazie!

  4. #4
    però c'è un però (sicuro sarà un'altra mi svista):
    codice:
                    <tbody>
                        <?php
                        $totQta = 0;
                        $totImp = 0;
                        $totQtaUscita = 0;
                        $totImpUscita = 0;
                        foreach ($queryPacc as $var):
                            $upNow = $var['uscita_pacc'];
                            $totQta += $var['sum_qta'];
                            $totImp += $var['imp_lordo'];
    
                            $totQtaUscita += $var['sum_qta'];
                            $totImpUscita += $var['imp_lordo'];
    
                            if (isset($upOld) && $upNow != $upOld):
                                ?>
                                <tr class="table-warning">
                                    <th>TOT <?php echo $upOld; ?></th>
                                    <th></th>
                                    <th></th>
                                    <th><?php echo $totQtaUscita; ?></th>
                                    <th><?php echo $totImpUscita; ?></th>
                                </tr>
                                <?php
                                $totQtaUscita = 0;
                                $totImpUscita = 0;
                            endif;
                            ?>
    
                            <tr>                         
                                <?php for ($i = 0; $i < count($arrColonne); $i++): ?>
                                    <td>
                                        <?php echo $var[array_values($arrColonne)[$i]]; ?>
                                    </td>
                                <?php endfor; ?>
                            </tr>
                            <?php
                            $upOld = $var['uscita_pacc'];
                        endforeach;
                        ?>
                        <tr class="table-warning">
                            <th>TOT <?php echo $upOld; ?></th>
                            <th></th>
                            <th></th>
                            <th><?php echo $totQtaUscita; ?></th>
                            <th><?php echo $totImpUscita; ?></th>
                        </tr>
                        <tr class="table-danger">
                            <th>TOTALE</th>
                            <th></th>
                            <th></th>
                            <th><?php echo $totQta; ?></th>
                            <th><?php echo $totImp; ?></th>
                        </tr>
                    </tbody>

    ho aggiunto i subtotali, solo che sono sbagliati.
    nel senso che al cambio di uscita, la somma si prende anche la prima riga dell'uscita successiva.

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.