Dimensions colonnes tableau PHP-->MySQL

Résolu
Bonjour,
je débute en programmation,
j'ai crée un tableau en PHP qui récupère les données d'une table (inscrits) MySQL.

j'ai un gros problème de dimenssionnement des colonnes, en fait je suis parti sur 2 tableaux un pour l'en tête, le deuxième pour les données...
je vous livre le code :
merci de votre aide
---------------------------------

<?php
echo "<div align=\"center\"><center><table border=\"1\">";
echo "<th width=20%>Nom</th>";
echo "<th width=20%>Prénom</th>";
echo "<th width=20%>Date</th>";
echo "<th width=5%>Sexe</th>";
echo "<th width=5%>Licence</th>";
echo "<th width=10%>Fédération</th>";
echo "<th width=20%>Numéro</th>";
?>
<?PHP
$db = mysql_connect("***", "***", "***");
mysql_select_db("***",$db);
$sql = "SELECT * FROM inscrits";
$req = mysql_query($sql) or die("Erreur SQL !".mysql_error());
while($data = mysql_fetch_array($req))
{
echo "<div align=\"center\"><center><table border=\"1\"> <tr> <td width=20%>";
echo $data['nom'];
echo "</td><td width=20%>";
echo $data['prenom'];
echo "</td><td width=20%>";
echo $data['date'];
echo "</td><td width=5%>";
echo $data['sexe'];
echo "</td><td width=5%>";
echo $data['licence'];
echo "</td><td width=10%>";
echo $data['federation'];
echo "</td><td width=20%>";
echo $data['numero'];
echo "</td></tr></table>";
}
mysql_close();
?>
</body>
</html>
Configuration: Windows XP Internet Explorer 7.0
Notepad
Kompozer

2 réponses

  1. merci Alain,

    ça fonctionne parfaitement...
    je le copie 100 fois !
    1
    1. Une seule table suffit, les dimensions sont fixées par la première ligne les autres vont se caler dessus

      il te manquait le balises <tr>

      <html>
      <body>
      <div align="center">
      	<table border="1">
      	<!-- il te manque les <tr>  </tr> -->
      		<tr>
      			<th width=20%>Nom</th>
      			<th width=20%>Pr&eacute;nom</th>
      			<th width=20%>Date</th>
      			<th width=5%>Sexe</th>
      			<th width=5%>Licence</th>
      			<th width=10%>F&eacute;d&eacute;ration</th>
      			<th width=20%>Num&eacute;ro</th>
      		<tr>';
      
      <?php
      		$db = mysql_connect("***", "***", "***");
      		mysql_select_db("***",$db);
      		$sql = "SELECT * FROM inscrits";
      		$req = mysql_query($sql) or die("Erreur SQL !".mysql_error());
      		mysql_close(); //on peut fermer la connexion mysql les résultats sonr en mémoire
      		while($data = mysql_fetch_array($req))
      		{
      			echo "<tr>"; //il faut un couple <tr></tr> par ligne
      			echo "<td>".$data['nom']."</td>";
      			echo "<td >".$data['prenom']."</td>";
      			echo "<td >".$data['date']."</td>";
      			echo "<td >".$data['sexe']."</td>";
      			echo "<td >".$data['licence']."</td>";
      			echo "<td >".$data['federation']."</td>";
      			echo "<td >".$data['numero']."</td>";
      			echo "</tr>";
      		}
      ?>	
      	</table>
      </div>
      
      </body>
      </html>
      0