IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

PHP & Base de données Discussion :

Total en dernière ligne d'un tableau [MySQL]


Sujet :

PHP & Base de données

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti
    Profil pro
    Inscrit en
    Décembre 2013
    Messages
    30
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2013
    Messages : 30
    Par défaut Total en dernière ligne d'un tableau
    Bonjour a tous,

    J'ai actuellement créé un tableau qui affiche les valeurs de la base de donnée.

    Je cherche a afficher en dernière ligne de ce tableau le total des différentes colonnes.

    Pour cela j'ai créé un deuxième tableau qui affichera les totaux.

    Je sais qu'il faut utiliser un "array_sum" mais après plusieurs test je cale.


    Quelqu'un aurait une idée ?

    Merci a vous.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    $result = mysqli_query($con,"SELECT * FROM Ca WHERE date LIKE '%$moisp%'");
     
    					echo "<table border='1'>
    					<tr >
    					<th bgcolor='#ffffff'>Jours</th>
    					<th bgcolor='#ffffff'>Budget CA France</th>
    					<th bgcolor='#ffffff'>Budget Qte France</th>
    					<th bgcolor='#ffffff'>CA France</th>
    					<th bgcolor='#ffffff'>Qte France</th>
    					<th bgcolor='#ffffff'>Budget CA Inter</th>
    					<th bgcolor='#ffffff'>Budget Qte Inter</th>
    					<th bgcolor='#ffffff'>CA Inter</th>
    					<th bgcolor='#ffffff'>Qte Inter</th>
    					</tr>";
     
    					while($row = mysqli_fetch_array($result)) {
     
    					if ($row['date'] == $JourPrecedent1){
    					$coloro = "<td bgcolor='#FFBF00' align=center>";
    					}
    					else {
    					$coloro = "<td bgcolor='#ffffff' align=center>";
    					}
     
    					  echo "<tr >";
    					  echo $coloro . substr($row['date'],0, 2) . "</td>";
    					  echo $coloro . $row['BudCaGdcptFrance'] . "</td>";
    					  echo $coloro . $row['BudQteGdcptFrance'] . "</td>";
    					  echo $coloro . $row['CaGdcptFrance'] . "</td>";
    					  echo $coloro . $row['QteGdcptFrance'] . "</td>";
    					  echo $coloro . $row['BudCaGdcptInter'] . "</td>";
    					  echo $coloro . $row['BudQteGdcptInter'] . "</td>";
    					  echo $coloro . $row['CaGdcptInter'] . "</td>";
    					  echo $coloro . $row['QteGdcptInter'] . "</td>";
    					  echo "</tr>";
     
    					}					
    echo "</table>";
    					echo "<table border='1'>
    					<tr >
    					<th bgcolor='#ffffff'>Total</th>
    					</tr>";
    					while($row = mysqli_fetch_array($result)) {
    					if ($row['date'] == $JourPrecedent1){
    					$coloro = "<td bgcolor='#FFBF00' align=center>";
    					}
    					else {
    					$coloro = "<td bgcolor='#ffffff' align=center>";
    					}
    					  echo "<tr >";
    					  echo $coloro . substr($row['BudCaGdcptFrance'],0, 2) . "</td>";
    					  echo "</tr>";
    					}					
    echo "</table>";
    }


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    25	19545		290852	10052	1294		0	0
    26	19545		0	0	1294		0	0
    27	19545		0	0	1294		0	0
    Total

  2. #2
    Modérateur
    Avatar de sabotage
    Homme Profil pro
    Inscrit en
    Juillet 2005
    Messages
    29 208
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations forums :
    Inscription : Juillet 2005
    Messages : 29 208
    Par défaut
    Tu confonds tableau HTML (table, tr, td etc.) et tableau PHP (array).

    Dans ton cas, je ferrais une deuxieme requête avec les SUM des colonnes que tu veux.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    SELECT SUM(QteGdcptFrance), SUM(BudCaGdcptInter) .....
    Au passage il manque toutes les ouvertures de <td> sur ton tableau.
    N'oubliez pas de consulter les FAQ PHP et les cours et tutoriels PHP

  3. #3
    Expert confirmé
    Avatar de rawsrc
    Homme Profil pro
    Dev indep
    Inscrit en
    Mars 2004
    Messages
    6 142
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 49
    Localisation : France, Bouches du Rhône (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Dev indep

    Informations forums :
    Inscription : Mars 2004
    Messages : 6 142
    Billets dans le blog
    12
    Par défaut
    Salut,

    tu peux aussi faire comme ça (j'ai repris la construction de ton tableau...)
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    $result = mysqli_query($con,"SELECT * FROM Ca WHERE date LIKE '%$moisp%'");
    $totaux = [
        'BudCaGdcptFrance'  => 0,
        'BudQteGdcptFrance' => 0,
        'CaGdcptFrance'     => 0,
        'QteGdcptFrance'    => 0,
        'BudCaGdcptInter'   => 0,
        'BudQteGdcptInter'  => 0,
        'CaGdcptInter'      => 0,
        'QteGdcptInter'     => 0
    ];
     
    echo <<<'html'
    <table border="1">
        <thead>
            <tr>
                <th bgcolor="#ffffff">Jours</th>
                <th bgcolor="#ffffff">Budget CA France</th>
                <th bgcolor="#ffffff">Budget Qte France</th>
                <th bgcolor="#ffffff">CA France</th>
                <th bgcolor="#ffffff">Qte France</th>
                <th bgcolor="#ffffff">Budget CA Inter</th>
                <th bgcolor="#ffffff">Budget Qte Inter</th>
                <th bgcolor="#ffffff">CA Inter</th>
                <th bgcolor="#ffffff">Qte Inter</th>
            </tr>
        </thead>
        <tbody>
    html;
     
        while ($row = mysqli_fetch_assoc($result))
        {
            // totaux
            foreach ($row as $k => $v)
            {            
                $totaux[$k] += $v;
            }
     
            $color = ($row['date'] == $JourPrecedent1) ? '#FFBF00' : '#FFFFFF';
            $jours = substr($row['date'], 0, 2);
            echo <<<html
                <tr>
                    <td bgcolor="{$color}" align="center">{$jours}</td>
                    <td bgcolor="{$color}" align="center">{$row['BudCaGdcptFrance']}</td>
                    <td bgcolor="{$color}" align="center">{$row['BudQteGdcptFrance']}</td>
                    <td bgcolor="{$color}" align="center">{$row['CaGdcptFrance']}</td>
                    <td bgcolor="{$color}" align="center">{$row['QteGdcptFrance']}</td>
                    <td bgcolor="{$color}" align="center">{$row['BudCaGdcptInter']}</td>
                    <td bgcolor="{$color}" align="center">{$row['BudQteGdcptInter']}</td>
                    <td bgcolor="{$color}" align="center">{$row['CaGdcptInter']}</td>
                    <td bgcolor="{$color}" align="center">{$row['QteGdcptInter']}</td>
                </tr>
    html;
        }
     
        echo <<<html
        </tbody>
        <tfoot>
            <tr>
                <td>Totaux</td>
                <td align="center">{$totaux['BudCaGdcptFrance']}</td>
                <td align="center">{$totaux['BudQteGdcptFrance']}</td>
                <td align="center">{$totaux['CaGdcptFrance']}</td>
                <td align="center">{$totaux['QteGdcptFrance']}</td>
                <td align="center">{$totaux['BudCaGdcptInter']}</td>
                <td align="center">{$totaux['BudQteGdcptInter']}</td>
                <td align="center">{$totaux['CaGdcptInter']}</td>
                <td align="center">{$totaux['QteGdcptInter']}</td>
            </tr>
        </tfoot>
    </table>            
    html;

  4. #4
    Membre averti
    Profil pro
    Inscrit en
    Décembre 2013
    Messages
    30
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2013
    Messages : 30
    Par défaut
    super cela fonctionne parfaitement

    un très grand merci a vous.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Sélectionner l'avant dernière ligne d'un tableau quelconque
    Par Erwan Narcos dans le forum Macros et VBA Excel
    Réponses: 3
    Dernier message: 11/01/2010, 12h25
  2. Réponses: 9
    Dernier message: 25/03/2009, 13h45
  3. Comment trouver la dernière ligne de mon tableau?
    Par thenico35 dans le forum Macros et VBA Excel
    Réponses: 8
    Dernier message: 03/03/2009, 14h35
  4. Tester quelle est la dernière ligne d'un tableau pour la remplir ?
    Par drthodt dans le forum Macros et VBA Excel
    Réponses: 9
    Dernier message: 29/07/2008, 13h26
  5. [CSS] Dernière ligne d'un tableau
    Par GLDavid dans le forum Mise en page CSS
    Réponses: 6
    Dernier message: 28/07/2006, 15h23

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo