Salut,
Je voudrais savoir comment on fait pour afficher une boucle dans un tableau sous cette forme avec un maximum de 6 affichage.
info1 info2 info3 (à la ligne)
info4 info5 info6 (à la ligne)
Merci beaucoup !
<?
/*Compte le nb de resultat pour afficher 3 résultats par ligne*/
$countres="SELECT COUNT(id) FROM itw";
$p = @mysql_query($countres);
$total = @mysql_result($p,'0','qte');
$req= "SELECT * FROM itw ORDER BY id DESC";
$res= mysql_query($req);
//déclaration de quelques variables
$nb=3;// Nombre de photos souhaiter par ligne
$i=0;
?>
<?
if ($total > 0)
{
?>
<table cellpadding="3" cellspacing="0" width="100%" border="1">
<?
while ($ligne = @mysql_fetch_array($res))
{
if ($i % $nb == 0)
{
?>
<tr>
<?
}
?> <td><table width="220" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="104" rowspan="2"><img src="img_itw/<? echo $ligne['img']; ?>" width="104" height="136"></td>
<td width="132" height="115" valign="top"><span class="bold"><? echo $ligne['nom']; ?></span><p><span class="text"><? echo $ligne['chapeau']; ?></span></td>
</tr>
<tr>
<? if($ligne['type'] == "collaborateur"){
echo"<td height ='21' background='img_itw/bg_collaborateur.jpg' align='center'>";}
elseif($ligne['type'] == "jeune avocat"){
echo"<td height ='21' background='img_itw/bg_jeuneavocat.jpg' align='center'>";}
elseif($ligne['type'] == "avocat indépendant"){
echo"<td height ='21' background='img_itw/bg_avocatinde.jpg' align='center'>";}
elseif($ligne['type'] == "associé"){
echo" <td heigh ='21' background='img_itw/bg_associe.jpg' align='center'>";}
elseif($ligne['type'] == "avocat étrangers"){
echo"<td height ='21' background='img_itw/bg_avocatetrangers.jpg' align='center'>";}?>
<a href="itw.php?id=<? echo $ligne['id']; ?>" class="white">Voir l'interview</a></td>
</tr>
</table> </td>
<?
if ($i % $nb == ($nb - 1))
{
?>
</tr>
<?
}
$i++;
}
if ($total % $nb == 0)
{
?>
</table>
<?
}
else
{
$reste = $nb - ($total % $nb
for ($j = 0; $j < $reste; $j++)
{
?>
<td> </td>
<?
}
?>
</tr>
</table>
<?
}
}
?>
Merci de votre aide.
<?
//--- une requête
$req = "SELECT * FROM itw ORDER BY id DESC";
//--- Résultat
$res = mysql_query($req);
while($data = mysql_fetch_array($res)) {
// on stocke nos données
$tablo[]=$data;
}
$nbcol=3; //--- détermine le nombre de colonnes de l'affichage
echo "<table width='100%' border='0' cellpadding='3' cellspacing='0'>";
for($i=0;$i<count($tablo);$i++){
if($i%$nbcol==0)
echo "<tr>";
echo "<td><table width='220' border='0' cellpadding='0' cellspacing='0'>
<tr>
<td width='104' rowspan='2'><img src='img_itw/".$tablo[$i]['img']."' width='104' height='136'></td>
<td width='132' height='115' valign='top'><span class='bold'>".$tablo[$i]['nom']."</span><p><span class='text'>".$tablo[$i]['chapeau']."</span></td>
</tr>
<tr>";
if($tablo[$i]['type'] == "collaborateur"){
echo"<td height ='21' background='img_itw/bg_collaborateur.jpg' align='center'>";}
elseif($tablo[$i]['type'] == "spécialisé"){
echo"<td height ='21' background='img_itw/bg_jeuneavocat.jpg' align='center'>";}
elseif($tablo[$i]['type'] == "avocat indépendant"){
echo"<td height ='21' background='img_itw/bg_avocatinde.jpg' align='center'>";}
elseif($tablo[$i]['type'] == "créateur"){
echo" <td heigh ='21' background='img_itw/bg_associe.jpg' align='center'>";}
elseif($tablo[$i]['type'] == "avocat étrangers"){
echo"<td height ='21' background='img_itw/bg_avocatetrangers.jpg' align='center'>";}
elseif($tablo[$i]['type'] == "plaidant"){
echo"<td height ='21' background='img_itw/bg_plaidant.jpg' align='center'>";}
echo"<a href='itw.php?id=". $tablo[$i]['id']."' class='white'>Voir l'interview</a></td>
</tr>
</table>
</td>";
if($i%$nbcol==($nbcol-1) or $i==(count($tablo)-1))
echo "</tr>";
}
echo "</table>";
?>
... hum hum... la clause LIMIT est toujours à la fin d'une requête APRÈS une éventuelle clause ORDER BYPour cela il te suffit d'utiliser la commande LIMIT juste avant le order by.