Récupération de données
Hors ligneDunbar Le 25/06/2006 à 20:07 Profil de Dunbar Configuration de Dunbar

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

<?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
Hors ligneWebdeb73 Le 26/06/2006 à 09:42 Profil de Webdeb73 Configuration de Webdeb73

Salut !

Apparemment ta base de données est mal conçue. Il aurait fallu faire qu'une seule fois tes histoires de ref, nom, date... Avec des requêtes SQL adaptées tu aurais pu faire ce que tu veux de façon propre et optimisée.

Maintenant ce que tu peux faire c'est faire une batterie de 6 if() dans ton while pour vérifier si les champs sont remplis ou non. Si oui alors tu affiches sinon rien.

Au passage, utilise mysql_fetch_assoc() à la place de mysql_fetch_array() car c'est plus optimisé.

++
--
Webmaster de http://www.webmaster-debutant.net
Hors ligneSweetdevil Le 29/06/2006 à 16:10 Profil de Sweetdevil Configuration de Sweetdevil

Viconaute ninja
Salut,

Je ne fais que passer mais: séparer le fond de la forme, ça peut servir aussi...

++
--
Linux, il y a moins bien mais c'est plus cher.
Vous avez résolu votre problème avec VIC ? Faites-le savoir sur les réseaux sociaux !
Vulgarisation-informatique.com
Cours en informatique & tutoriels