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

Langage PHP Discussion :

Alterner Couleur ligne tableau php


Sujet :

Langage PHP

  1. #1
    Membre à l'essai
    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
    Points : 21
    Points
    21
    Par défaut Alterner Couleur ligne tableau php
    Bonjour,
    Voici quelque jours que j'essaye de faire alterner les couleurs dans mon 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
     
    echo "<table >
    <tr>
    <th>Numero de commande</th>
    <th>Date de Commande</th>
    <th>Date Livraison demandée</th>
    <th>N° Article</th>
    <th>Qté Commandé</th>
    <th>Qté Livré</th>
    <th>Qte restant à livrer</th>
    <th>Unit Price</th>
    <th>MT en Commande</th>
    <th>Origine Commande</th>
    <th>N° Document Origine</th>
    <th>AvailableDate</th>
    <th>Disponibilité</th>
    </tr>";
     
     
     
    while($row = mysqli_fetch_array($result)) {
     
        echo "<tr >";
        echo "<td width=7%>" . $row['N° Commande'] . "</td>";
        echo "<td width=5%>" . $row['Date Commande'] . "</td>";
        echo "<td width=6%>" . $row['Date Livraison demandée'] . "</td>";
        echo "<td align=center>" . $row['N° Article'] . "</td>";
        echo "<td align=center width=1%>" . $row['Qté Commandé'] . "</td>";
    	echo "<td align=center width=3%>" . $row['Qté Livré'] . "</td>";
        echo "<td align=center width=3%>" . $row['Qte restant à livrer'] . "</td>";
        echo "<td align=center>" . $row['Unit Price'] . "</td>";
        echo "<td  align=center width=5%>" . $row['MT en Commande'] . "</td>";
    	echo "<td align=center>" . $row['Origine Commande'] . "</td>";
        echo "<td width=10%>" . $row['N° Document Origine'] . "</td>";
    	echo "<td width=5%>" . $row['AvailableDate'] . "</td>";
    	echo "<td  align=center width=8% style=\"background-color: ";
    	if($row['Disponibilité'] == 'Réapro en cour') {
    		echo 'orange';
    	} elseif($row['Disponibilité'] == 'En stock') {
    		echo 'green';
    	} elseif($row['Disponibilité'] == 'Epuisé') {
    		echo 'red';
    	}
    	echo '">'. $row['Disponibilité'].'</span></td></tr>';
    }
     
     
     
     
    echo "</table>";
    J'ai essayé tout un tas de tuto sur openclass room mais ca ne fonctionne jamais.

    Auriez vous un début d'idée ?
    Merci beaucoup

  2. #2
    Modérateur
    Avatar de Kreepz
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Juin 2011
    Messages
    681
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 32
    Localisation : France, Finistère (Bretagne)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Distribution

    Informations forums :
    Inscription : Juin 2011
    Messages : 681
    Points : 1 458
    Points
    1 458
    Billets dans le blog
    1
    Par défaut
    Bonjour,

    Pourrais-tu mettre le rendu html ?

  3. #3
    Membre à l'essai
    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
    Points : 21
    Points
    21
    Par défaut
    je me repond a moi meme j'ai trouvé en definitive

    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
    echo "<table >
    <tr>
    <th>Numero de commande</th>
    <th>Date de Commande</th>
    <th>Date Livraison demandée</th>
    <th>N° Article</th>
    <th>Qté Commandé</th>
    <th>Qté Livré</th>
    <th>Qte restant à livrer</th>
    <th>Unit Price</th>
    <th>MT en Commande</th>
    <th>Origine Commande</th>
    <th>N° Document Origine</th>
    <th>AvailableDate</th>
    <th>Disponibilité</th>
    </tr>";
     
     
     
     
    $i = 0;
    while($row = mysqli_fetch_array($result)) {
        if ($i++ & 1) {
            echo '<tr class="ligne_impaire">';
        } else {
            echo '<tr class="ligne_paire">';
        }
        // ...
     
     
        echo "<td width=7%>" . $row['N° Commande'] . "</td>";
        echo "<td width=5%>" . $row['Date Commande'] . "</td>";
        echo "<td width=6%>" . $row['Date Livraison demandée'] . "</td>";
        echo "<td align=center>" . $row['N° Article'] . "</td>";
        echo "<td align=center width=1%>" . $row['Qté Commandé'] . "</td>";
    	echo "<td align=center width=3%>" . $row['Qté Livré'] . "</td>";
        echo "<td align=center width=3%>" . $row['Qte restant à livrer'] . "</td>";
        echo "<td align=center>" . $row['Unit Price'] . "</td>";
        echo "<td  align=center width=5%>" . $row['MT en Commande'] . "</td>";
    	echo "<td align=center>" . $row['Origine Commande'] . "</td>";
        echo "<td width=10%>" . $row['N° Document Origine'] . "</td>";
    	echo "<td width=5%>" . $row['AvailableDate'] . "</td>";
    	echo "<td  align=center width=8% style=\"background-color: ";
    	if($row['Disponibilité'] == 'Réapro en cour') {
    		echo 'orange';
    	} elseif($row['Disponibilité'] == 'En stock') {
    		echo 'green';
    	} elseif($row['Disponibilité'] == 'Epuisé') {
    		echo 'red';
    	}
    	echo '">'. $row['Disponibilité'].'</span></td></tr>';
    }
    le code CSS

    Code css : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    .ligne_paire{
        background-color : #CCCCCC;
    }
     
    /* Cible les lignes impaires. */
    .ligne_impaire{
        background-color : #999999;
    }


    Merci a Kreepz d'avoir répondu.

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

Discussions similaires

  1. [MySQL] Retour ligne tableau PHP HTML
    Par iMax92 dans le forum PHP & Base de données
    Réponses: 6
    Dernier message: 03/03/2013, 16h06
  2. alternance couleur sur tableau dynamique
    Par asus02 dans le forum Langage
    Réponses: 25
    Dernier message: 13/11/2011, 01h49
  3. changer couleur ligne tableau
    Par xouzi dans le forum Général JavaScript
    Réponses: 8
    Dernier message: 18/08/2011, 14h19
  4. changer couleur ligne tableau
    Par philippe123 dans le forum Général JavaScript
    Réponses: 2
    Dernier message: 17/02/2007, 15h19
  5. Visual Studio: Affichage tableau, alterner couleur ligne
    Par en_stage dans le forum MS SQL Server
    Réponses: 4
    Dernier message: 17/08/2006, 22h41

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