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 :

Formatage des données dans un tableau [MySQL]


Sujet :

PHP & Base de données

  1. #1
    Membre régulier
    Inscrit en
    Juin 2006
    Messages
    215
    Détails du profil
    Informations forums :
    Inscription : Juin 2006
    Messages : 215
    Points : 79
    Points
    79
    Par défaut Formatage des données dans un tableau
    Bonjour,

    J'ai un formulaire avec 6 lignes et 5 champs, j'ai une base qui récupére les donnée du formulaire, et j'ai un tableau qui lie les données de la table.
    Mon problème est que le formulaire est rempli une fois par jour, mais pas obligatoirement les 6 lignes (lundi 3 lignes, mardi 6 lignes, mercredi 2 lignes ,etc...)

    Mais mon tableau affiche les 6 lignes à chaque enregistrement du formulaire que les lignes soit remplie ou pas.
    cela fait que je me retrouve avec un tableau dans lequel j'ai des lignes vide (c'est pas trés jolie !)

    Mon fichier lecture.php

    Code php : 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
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
     
    <?php
    // information pour la connection à le DB
    $host = 'localhost';
    $user = 'xxxxx';
    $pass = 'xxxxxxxxx';
    $db = 'vd-xxxxxxxxx';
     
    // connection à la DB
    $link = mysql_connect ($host,$user,$pass) or die ('Erreur : '.mysql_error() );
    mysql_select_db($db) or die ('Erreur :'.mysql_error());
    $select = 'SELECT ref_1,nom_1,adr_1,rem_1,tech_1,date_1,tel_1,ref_2,nom_2,adr_2,rem_2,tech_2,date_2,tel_2,ref_3,nom_3,adr_3,rem_3,tech_3,date_3,tel_3,ref_4,nom_4,adr_4,rem_4,tech_4,date_4,tel_4,ref_5,nom_5,adr_5,rem_5,tech_5,date_5,tel_5,ref_6,nom_6,adr_6,rem_6,tech_6,date_6,tel_6 FROM 2webmaster';
     
    $result = mysql_query($select,$link) or die ('Erreur : '.mysql_error() );
    $total = mysql_num_rows($result);
     
     
     
    // si on a récupéré un résultat on l'affiche.
    if($total) {
    // debut du tableau
    echo '<center><table border="0,5" bgcolor="#CCCCCC">'."n";
    // première ligne on affiche les titres prénom et surnom dans 2 colonnes
    echo '<tr>';
    echo '<td bgcolor="#CCFFFF"><font size="2"><u>Réf Client</u></font></td>';
    echo '<td bgcolor="#CCFFFF"><font size="2"><u>Nom</u></font></td>';
    echo '<td bgcolor="#CCFFFF"><font size="2"><u>Adresse</u></font></td>';
    echo '<td bgcolor="#CCFFFF"><font size="2"><u>Remarques</u></font></td>';
    echo '<td bgcolor="#CCFFFF"><font size="2"><u>N°Tél</u></font></td>' ;
    echo '<td bgcolor="#CCFFFF"><font size="2"><u>Date</u></font></td>' ;
    echo '<td bgcolor="#CCFFFF"><font size="2"><u>Nom du technicien</u></font></td>' ;
     
    echo '</tr>'."n";
    // lecture et affichage des résultats sur 2 colonnes, 1 résultat par ligne. 
    while($row = mysql_fetch_array($result)) {
    echo '<tr>';
    echo '<td bgcolor="#FFFFFF"><font size="2">'.$row["ref_1"].'</font></td>';
    echo '<td bgcolor="#FFFFFF"><font size="2">'.$row["nom_1"].'</font></td>';
    echo '<td bgcolor="#FFFFFF"><font size="2">'.$row["adr_1"].'</font></td>';
    echo '<td bgcolor="#FFFFFF"><font size="2">'.$row["rem_1"].'</font></td>';
    echo '<td bgcolor="#FFFFFF"><font size="2">'.$row["tel_1"].'</font></td>';
    echo '<td bgcolor="#FFFFFF"><font size="2">'.$row["date_1"].'</font></td>';
    echo '<td bgcolor="#FFFFFF"><font size="2">'.$row["tech_1"].'</font></td>';
    echo '</tr>'."n";
    echo '<tr>';
    echo '<td bgcolor="#FFFFFF"><font size="2">'.$row["ref_2"].'</font></td>';
    echo '<td bgcolor="#FFFFFF"><font size="2">'.$row["nom_2"].'</font></td>';
    echo '<td bgcolor="#FFFFFF"><font size="2">'.$row["adr_2"].'</font></td>';
    echo '<td bgcolor="#FFFFFF"><font size="2">'.$row["rem_2"].'</font></td>';
    echo '<td bgcolor="#FFFFFF"><font size="2">'.$row["tel_2"].'</font></td>';
    echo '<td bgcolor="#FFFFFF"><font size="2">'.$row["date_2"].'</font></td>';
    echo '<td bgcolor="#FFFFFF"><font size="2">'.$row["tech_2"].'</font></td>';
    echo '</tr>'."n";
    echo '<tr>';
    echo '<td bgcolor="#FFFFFF"><font size="2">'.$row["ref_3"].'</font></td>';
    echo '<td bgcolor="#FFFFFF"><font size="2">'.$row["nom_3"].'</font></td>';
    echo '<td bgcolor="#FFFFFF"><font size="2">'.$row["adr_3"].'</font></td>';
    echo '<td bgcolor="#FFFFFF"><font size="2">'.$row["rem_3"].'</font></td>';
    echo '<td bgcolor="#FFFFFF"><font size="2">'.$row["tel_3"].'</font></td>';
    echo '<td bgcolor="#FFFFFF"><font size="2">'.$row["date_3"].'</font></td>';
    echo '<td bgcolor="#FFFFFF"><font size="2">'.$row["tech_3"].'</font></td>';
    echo '</tr>'."n";
    echo '<tr>';
    echo '<td bgcolor="#FFFFFF"><font size="2">'.$row["ref_4"].'</font></td>';
    echo '<td bgcolor="#FFFFFF"><font size="2">'.$row["nom_4"].'</font></td>';
    echo '<td bgcolor="#FFFFFF"><font size="2">'.$row["adr_4"].'</font></td>';
    echo '<td bgcolor="#FFFFFF"><font size="2">'.$row["rem_4"].'</font></td>';
    echo '<td bgcolor="#FFFFFF"><font size="2">'.$row["tel_4"].'</font></td>';
    echo '<td bgcolor="#FFFFFF"><font size="2">'.$row["date_4"].'</font></td>';
    echo '<td bgcolor="#FFFFFF"><font size="2">'.$row["tech_4"].'</font></td>';
    echo '</tr>'."n"; 
    echo '<tr>';
    echo '<td bgcolor="#FFFFFF"><font size="2">'.$row["ref_5"].'</font></td>';
    echo '<td bgcolor="#FFFFFF"><font size="2">'.$row["nom_5"].'</font></td>';
    echo '<td bgcolor="#FFFFFF"><font size="2">'.$row["adr_5"].'</font></td>';
    echo '<td bgcolor="#FFFFFF"><font size="2">'.$row["rem_5"].'</font></td>';
    echo '<td bgcolor="#FFFFFF"><font size="2">'.$row["tel_5"].'</font></td>';
    echo '<td bgcolor="#FFFFFF"><font size="2">'.$row["date_5"].'</font></td>';
    echo '<td bgcolor="#FFFFFF"><font size="2">'.$row["tech_5"].'</font></td>';
    echo '</tr>'."n";
    echo '<tr>';
    echo '<td bgcolor="#FFFFFF"><font size="2">'.$row["ref_6"].'</font></td>';
    echo '<td bgcolor="#FFFFFF"><font size="2">'.$row["nom_6"].'</font></td>';
    echo '<td bgcolor="#FFFFFF"><font size="2">'.$row["adr_6"].'</font></td>';
    echo '<td bgcolor="#FFFFFF"><font size="2">'.$row["rem_6"].'</font></td>';
    echo '<td bgcolor="#FFFFFF"><font size="2">'.$row["tel_6"].'</font></td>';
    echo '<td bgcolor="#FFFFFF"><font size="2">'.$row["date_6"].'</font></td>';
    echo '<td bgcolor="#FFFFFF"><font size="2">'.$row["tech_6"].'</font></td>';
    echo '</tr>'."n"; 
    }
    echo '</table></center>'."n";
    // fin du tableau.
    }
    else echo 'Pas d'enregistrements dans cette table...';
    
    // on libère le résultat
    mysql_free_result($result);
    
    ?>
    </font>
    </body>
    </html>

    Merci d'avance

  2. #2
    Membre éprouvé
    Avatar de Biglo
    Profil pro
    Inscrit en
    Juillet 2002
    Messages
    537
    Détails du profil
    Informations personnelles :
    Localisation : France, Moselle (Lorraine)

    Informations forums :
    Inscription : Juillet 2002
    Messages : 537
    Points : 984
    Points
    984
    Par défaut
    Salut

    C'est une question en rapport avec PHP et non MySQL.

    Il suffit que tu testes si ref2, ref3, ... ne sont pas vides avant de les afficher.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    if (!empty($row['ref_2']))
    {
       echo '...';
    }
    if (!empty($row['ref_3']))
    {
       echo '...';
    }
    La structure de ta base de données n'est vraiment pas géniale, mais tu as déjà été conseillé dans ton post "Form base tableaux"...

  3. #3
    Membre expert
    Avatar de Alexandre T
    Homme Profil pro
    Chef de projets AMO
    Inscrit en
    Mai 2002
    Messages
    1 213
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 47
    Localisation : France, Gironde (Aquitaine)

    Informations professionnelles :
    Activité : Chef de projets AMO
    Secteur : Transports

    Informations forums :
    Inscription : Mai 2002
    Messages : 1 213
    Points : 3 001
    Points
    3 001
    Par défaut
    Problème PHP / MySQL => Je déplace dans le forum PHP sous Forum SGBD.
    Alexandre Tranchant
    Chef de projet AMO pour le Cerema.
    Retrouvez mes articles sur PHP et Symfony

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

Discussions similaires

  1. Structurer des données dans un tableau
    Par julie75 dans le forum Débuter
    Réponses: 21
    Dernier message: 18/12/2007, 23h20
  2. [Conception] Recuperer des données dans un tableau dynamique
    Par Tartanjet dans le forum PHP & Base de données
    Réponses: 1
    Dernier message: 05/09/2006, 00h28
  3. Réponses: 6
    Dernier message: 17/07/2006, 15h07
  4. [MySQL] Stocker des données dans un tableau
    Par LadyArwen dans le forum PHP & Base de données
    Réponses: 3
    Dernier message: 02/02/2006, 10h40
  5. Réponses: 3
    Dernier message: 05/12/2005, 02h30

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