1 pièce(s) jointe(s)
Afficher un tableau avec php mysql
Bonsoir,
J'essaie de faire un tableau à partir de données SQL en PHP toutefois, je n'arrive pas à afficher en HTML sur la même ligne par exemple la vente de Papaye 2006 et 2007, elle s'affiche sur deux lignes différentes (voir fichier jpg joint).
Voilà le code :
Code:
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
| <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr">
<head>
<title>tableau la Halde</title>
<meta http-equiv="Content-Language" content="fr" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<script src="javascript/jquery.js" type="text/javascript"></script>
<script src="javascript/style.js" type="text/javascript"></script>
</head>
<body>
<?php
//Connexion au serveur MySQL
$db=mysql_connect("localhost","xxxx","xxxxx") or die ("erreur de connexion".mysql_error());
//ouverture de la base
mysql_select_db("vpc",$db)or die("erreur de connexion à la base xxx");
$select = 'SELECT id, annee, type, nombre FROM fruit';
$result = mysql_query($select) or die ('Erreur : '.mysql_error() );
//$total = mysql_num_rows($result);
//if($total) {
echo "<table class='vision'>" //la class vision permet de faire appel au jquery + css
?>
<caption>Vente de fruits</caption>
<thead>
<tr>
<th>type</th>
<th>2006</th>
<th>2007</th>
</tr>
</thead>
<tbody>
<tr>
<?php while($row = mysql_fetch_array($result)) { ?>
<td><?php echo $row['type'];?></td>
<td> <?php if($row['annee']=='2006')
echo $row['nombre'];?></td>
<td><?php if($row['annee']=='2007')
echo $row['nombre'];?></td>
</tr>
<?php } //pour finir la boucle?>
</tbody>
<?php
echo "</table>";
?>
</body>
</html> |
Qui aurait une piste pour améliorer cela?
Merci beaucoup.
slnprojet