Page 1 sur 1

Formater un tableau

Posté : 22 août 2006, 05:53
par Mike_php
Bonsoir, j'aime bien ce forum et vous êtes très efficaces les copins.
J'ai toujours construit mes sites avec Frontpage, donc je n'ai jamais eu vraiment besoin de coder en HTML ou PHP. De plus je suis visuel et là avec PHP je n'arrive pas à formater mon tableau.

J'aimerais que ça soit 1 tableau et non plusieurs tableaux les un sur les autres et que les rangés soit tous égaux en largeurs mais pas nécessairement en hauteur, car tout dépend du texte.

De plus, j'aimerais que les titres de mes colonnes ne se répète pas ou si possible reste toujours afficher en haut quand on scroll.

Merci et bonne soirée!

Voici ce que mon tableau a l'air:
http://www.alpha-mpda.org/test/afficher2.php

Voici mon code:
<?PHP

$db = mysql_connect('localhost', '*****', '******'); 
mysql_select_db('******',$db); 

$sql = 'SELECT * FROM webalpha'; 
$req = mysql_query($sql) or die('Erreur SQL !
'.$sql.'
'.mysql_error()); 
while($data = mysql_fetch_array($req)) 
{echo "<div align=left>
<table border=1  >
<th> Site Web</th>
<th> Cat&eacute;gorie </th>
<th> Niveau </th>
<th> Sorte </th>
<th> Pour&nbsp;qui </th>
<th> Commentaire </th>
<th> Date </th>
<tr>
<td align= center width=250>";
echo '<a target="_blank" href= "'.$data['adresse_Web'].'"> <img src="webalpha/'.$data['image'].'"></a>'; 
echo "</td> 
<td  align= center width=50 >"; 
echo $data['categorie']; 
echo "</td> 
<td align= center width=50>";
echo $data['niveau']; 
echo "</td> 
<td align= center width=50>";
echo $data['sorte']; 
echo "</td> 
<td align= center width=50>";
echo $data['pourQui']; 
echo "</td> 
<td align= center width=200>";
echo $data['commentaire']; 
echo "</td> 
<td align= center width=50>";
echo $data['Date'];
echo "</td> 
</tr> 
</table> 
</div>";} 
mysql_close();
?> 

Posté : 22 août 2006, 07:27
par jpaul
Bonjour,

Il me semble qu'une bonne partie de ta question pourrait être résolue avec le fait de sortir l'ouverture et la fermeture de la table de la boucle while (pour ce la je virerais aussi le div).
Ca donnerait quelque chose comme ça :
<?PHP

$db = mysql_connect('localhost', '*****', '******'); 
mysql_select_db('******',$db); 

$sql = 'SELECT * FROM webalpha'; 
$req = mysql_query($sql) or die('Erreur SQL !
'.$sql.'
'.mysql_error()); 
// affichage du début de la table
echo "
<table border=1  >
<th> Site Web</th>
<th> Cat&eacute;gorie </th>
<th> Niveau </th>
<th> Sorte </th>
<th> Pour&nbsp;qui </th>
<th> Commentaire </th>
<th> Date </th>
";
while($data = mysql_fetch_array($req)) 
{
// affichage des lignes de la table
echo "
<tr>
<td align= center width=250>";
echo '<a target="_blank" href= "'.$data['adresse_Web'].'"> <img src="webalpha/'.$data['image'].'"></a>'; 
echo "</td> 
<td  align= center width=50 >"; 
echo $data['categorie']; 
echo "</td> 
<td align= center width=50>";
echo $data['niveau']; 
echo "</td> 
<td align= center width=50>";
echo $data['sorte']; 
echo "</td> 
<td align= center width=50>";
echo $data['pourQui']; 
echo "</td> 
<td align= center width=200>";
echo $data['commentaire']; 
echo "</td> 
<td align= center width=50>";
echo $data['Date'];
echo "</td> 
</tr> 

";} 
// affichage de la fin de la table
echo "</table>"; 
mysql_close();
?>

Posté : 22 août 2006, 08:36
par Mike_php
Merci jpaul, c'est exactement ça que je cherchais. :D

Bonne soirée!

Posté : 22 août 2006, 09:33
par jpaul
Merci jpaul, c'est exactement ça que je cherchais. :D

Bonne soirée!
De rien, content d'avoir pu t'aider.
N'oublies pas le bouton résolu :)