Comment obtenir un tel affichage en exploitant plusieurs résultats de ma base de donnée ?----------- CHAMP1 ----- CHAMP2 ----- CHAMP3
tuple1 ------ val1-----------val2-----------val3---
tuple2 ------ val4-----------val5-----------val6---
tuple3 ------ val7-----------val8-----------val9---
$html = "<table>";
$field_listed = false;
$fields = array();
//On fait la requête
$result = mysql_query("ta requete");
//On boucle sur les résutats
while($row = mysql_fetch_assoc($result))
{
//Si on a pas encore construit la liste des champs, on le fait
if(!$field_listed)
{
//On liste tous les champs retournés
$fields = array_keys($row);
//On affiche la liste des champs
$html .= '<tr>';
foreach($fields as $k => $field)
$html .= '<th>'.$field.'</th>';
$html .= '</tr>';
//On flag a true pour ne plus rentrer dans cette condition lors de la prochaine boucle
$field_listed = true;
}
// On affiche le contenu du tuple courant
$html .= '<tr>';
foreach($fields as $k => $field)
{
$html .= '<td>'.$row[$field].'</td>';
}
$html .= '</tr>';
}
$html .= "</table>";
Ta variable $html contient donc un tableau (au sens html du terme) dont la première ligne est composée des champs et toutes les lignes suivantes des valeurs associées à ces champs.Code : Tout sélectionner
<table>
<tr>
<th>Champ1</th>
<th>Champ2</th>
<th>Champ3</th>
</tr>
<tr>
<td>val1</td>
<td>val2</td>
<td>val3</td>
</tr>
<tr>
<td>val4</td>
<td>val5</td>
<td>val6</td>
</tr>
<tr>
<td>val7</td>
<td>val8</td>
<td>val9</td>
</tr>
</table>
echo "<table align='center' border='1' bordercolor='yellow' width='2160'>
<tr>
<td width='40' align='center'><font color='white'size='5'><b>id</b></font></td>
<td width='80' align='center'><font color='white'size='5'><b>jour</b></font></td>
<td width='200' align='center'><font color='white'size='5'><b>commande</b></font></td>
<td width='150' align='center'><font color='white'size='5'><b>produit</b></font></td>
<td width='80' align='center'><font color='white'size='5'><b>marque</b></font></td>
<td width='200' align='center'><font color='white'size='5'><b>designation</b></font></td>
<td width='100' align='center'><font color='white'size='5'><b>sequence</b></font></td>
<td width='100' align='center'><font color='white'size='5'><b>etat</b></font></td>
<td width='250' align='center'><font color='white'size='5'><b>commentaire</b></font></td>
<td width='200' align='center'><font color='white'size='5'><b>serie</b></font></td>
<td width='80' align='center'><font color='white'size='5'><b>date</b></font></td>
<td width='400' align='center'><font color='white'size='5'><b>affectation</b></font></td>
<td width='200' align='center'><font color='white'size='5'><b>nom</b></font></td>
</tr>
</table>";
$reponse = mysql_query("SELECT * FROM Pcs");
while ($donnees = mysql_fetch_array($reponse) )
{
$id = $donnees['id'];
$jour = $donnees['jour'];
$commande = $donnees['commande'];
$produit = $donnees['produit'];
$marque = $donnees['marque'];
$designation = $donnees['designation'];
$sequence = $donnees['sequence'];
$etat = $donnees['etat'];
$commentaire = $donnees['commentaire'];
$serie = $donnees['serie'];
$date = $donnees['date'];
$affectation = $donnees['affectation'];
$nom = $donnees['nom'];
echo "<table align='center' border='1' bordercolor='yellow' width='2160'>
<tr>
<td width='40'> <font color='white'>$id </font></td>
<td width='80'> <font color='white'>$jour </font></td>
<td width='200'> <font color='white'>$commande </font></td> <td width='150'> <font color='white'>$produit </font></td>
<td width='80'> <font color='white'>$marque </font></td>
<td width='200'> <font color='white'>$designation </font></td>
<td width='100'> <font color='white'>$sequence </font></td>
<td width='100'> <font color='white'>$etat </font></td>
<td width='250'> <font color='white'>$commentaire </font></td>
<td width='200'> <font color='white'>$serie </font></td>
<td width='80'> <font color='white'>$date </font></td>
<td width='400'> <font color='white'>$affectation </font></td>
<td width='200'> <font color='white'>$nom </font></td>
</tr>
</table>";
}
// ...
<style type="text/css">
table { align:center ; border:1px #FFFF00 ; }
th { align:center ; font-size:10px ; font-weight:bold ; color:#FFFFFF ; }
td { align:center ; font-size:10px ; }
</style>
</head>
<body>
<table width='2160'>
<tr>
<td width='40' >id</td>
<td width='80' >jour</td>
<td width='200'>commande</td>
<td width='150'>produit</td>
<td width='80' >marque</td>
<td width='200'>designation</td>
<td width='100'>sequence</td>
<td width='100'>etat</td>
<td width='250'>commentaire</td>
<td width='200'>serie</td>
<td width='80' >date</td>
<td width='400'>affectation</td>
<td width='200'>nom</td>
</tr>
<?php
$reponse = mysql_query("SELECT * FROM Pcs");
while ($donnees = mysql_fetch_assoc($reponse) )
{ extract($donnees);
?>
<tr>
<td><?php echo $id; ?></td>
<td><?php echo $jour; ?></td>
<td><?php echo $commande; ?></td>
<td><?php echo $produit; ?></td>
<td><?php echo $marque; ?></td>
<td><?php echo $designation; ?></td>
<td><?php echo $sequence; ?></td>
<td><?php echo $etat; ?></td>
<td><?php echo $commentaire; ?></td>
<td><?php echo $serie; ?></td>
<td><?php echo $date; ?></td>
<td><?php echo $affectation; ?></td>
<td><?php echo $nom; ?></td>
</tr>
<?php
}
?>
</table>
<?php
$reponse = mysql_query("SELECT * FROM Pcs");
while ($donnees = mysql_fetch_assoc($reponse) )
{ extract($donnees);
?>
<tr>
<td><?php echo $id; ?></td>
<td><?php echo $jour; ?></td>
<td><?php echo $commande; ?></td>
<td><?php echo $produit; ?></td>
<td><?php echo $marque; ?></td>
<td><?php echo $designation; ?></td>
<td><?php echo $sequence; ?></td>
<td><?php echo $etat; ?></td>
<td><?php echo $commentaire; ?></td>
<td><?php echo $serie; ?></td>
<td><?php echo $date; ?></td>
<td><?php echo $affectation; ?></td>
<td><?php echo $nom; ?></td>
</tr>
<?php
}
?>