8791 sujets

Développement web côté serveur, CMS

Bonjour,

J'aimerai afficher les enregistrements de ma table groupe deux par ligne car la lorsque je les affiche ils apparaissent tous l'un en dessous de l'autre.


Voici mon code :

<? 
$sql = "SELECT num_groupe, nom_groupe, img_groupe FROM groupe Group By num_groupe";
$sql_exe = mysql_query($sql) or die('Erreur : ' . mysql_error());
while ($Tab = mysql_fetch_array($sql_exe)) 
{ 
?> 
<br><table width="860" height="0" border="0" cellpadding="0" cellspacing="0">
<tr> 
<td width="860" height="200" valign="top" align="center"> 
<table width="420" cellpadding="0" cellspacing="0" border="0"> 
<tr> 
<td background="images/cadre_01.gif" width="5" height="5"></td> 
<td background="images/cadre_02.gif" width="410" height="5"></td> 
<td background="images/cadre_03.gif" width="5" height="5"></td> 
</tr> 
</table> 
<table width="420" cellpadding="0" cellspacing="0"> 
<tr> 
<td background="images/cadre_04.gif" width="5" height="190"></td> 

<td background="images/cadre_05.gif" width="410" height="190" valign="top" align="center"> 
<span class="nom_groupe"><?php echo $Tab["nom_groupe"]; ?>  
</span> 
<br><br> 
<img src="images/<?php echo $Tab['img_groupe']; ?>  
"> 
</td> 

<td background="images/cadre_06.gif" width="5" height="190"></td> 
</tr> 
</table> 
<table width="420" cellpadding="0" cellspacing="0"> 
<tr> 
<td background="images/cadre_07.gif" width="5" height="5"></td> 
<td background="images/cadre_08.gif" width="410" height="5"></td> 
<td background="images/cadre_09.gif" width="5" height="5"></td> 
</tr> 
</table> 
</td> 

</tr>
</table>
<?php } ?>  


Il ne me manque plus que ça à mettre en place et j'ai terminé mais je ne vois pas trop comment faire.

Merci
Bonjour,

Je ne comprend pas ton code désoler, mais si j'ai compris, il suffirait que dans un premier temps tu inseres toutes tes données dans un tableau dans ce style.


$i=0;
while ($Tab = mysql_fetch_array($sql_exe)) {
$tableau[$i]=$Tab;
$i++;
}


Comme cela après tu peux tranquillement les afficher deux par deux. Avec un for tu fais une boucle et pour appeler la ligne suivant tu auras juste a faire un +1 avec une petit verification pour voir s'il est present.

for($i=0;$i<count($tableau);$i++){
echo $tableau[$i];
if(isset($tableau[$i+1])){
echo $tableau[$i+1];
}
$i++;
}


Je pense que cela devrai regler ton probleme a moins que je ne me soit tromper.
ça marche en partie, en fait ça m'affiche mon premier groupe une fois, puis mes deux groupes l'un à coté de l'autre juste en dessous

voila mon code


<? 
$sql = "SELECT num_groupe, nom_groupe, img_groupe FROM groupe Group By num_groupe";
$sql_exe = mysql_query($sql) or die('Erreur : ' . mysql_error());
$i=0;
while ($Tab = mysql_fetch_array($sql_exe)) {
$tableau[$i]=$Tab;
$i++;

?>   

	 <br><table width="860" height="0" border="0" cellpadding="0" cellspacing="0">
    <tr>
<?
	 for($i=0;$i<count($tableau);$i++){
?>   
      <td width="860" height="200" valign="top" align="center"> 
            <table width="420" cellpadding="0" cellspacing="0" border="0"> 
              <tr> 
                <td background="images/cadre_01.gif" width="5" height="5"></td> 
                <td background="images/cadre_02.gif" width="410" height="5"></td> 
                <td background="images/cadre_03.gif" width="5" height="5"></td> 
              </tr> 
            </table> 
            <table width="420" cellpadding="0" cellspacing="0"> 
              <tr> 
                <td background="images/cadre_04.gif" width="5" height="190"></td> 

                <td background="images/cadre_05.gif" width="410" height="190" valign="top" align="center"> 
                <span class="nom_groupe"><?php echo $tableau[$i]["nom_groupe"]; ?></span> 
                <br><br> 
                <img src="images/<?php echo $tableau[$i]['img_groupe']; ?>"> 
                </td> 
                 
                <td background="images/cadre_06.gif" width="5" height="190"></td> 
              </tr> 
            </table> 
            <table width="420" cellpadding="0" cellspacing="0"> 
              <tr> 
                <td background="images/cadre_07.gif" width="5" height="5"></td> 
                <td background="images/cadre_08.gif" width="410" height="5"></td> 
                <td background="images/cadre_09.gif" width="5" height="5"></td> 
              </tr> 
            </table> 
         </td> 
<?
if(isset($tableau[$i+1])){
?>
      <td width="860" height="200" valign="top" align="center"> 
            <table width="420" cellpadding="0" cellspacing="0" border="0"> 
              <tr> 
                <td background="images/cadre_01.gif" width="5" height="5"></td> 
                <td background="images/cadre_02.gif" width="410" height="5"></td> 
                <td background="images/cadre_03.gif" width="5" height="5"></td> 
              </tr> 
            </table> 
            <table width="420" cellpadding="0" cellspacing="0"> 
              <tr> 
                <td background="images/cadre_04.gif" width="5" height="190"></td> 

                <td background="images/cadre_05.gif" width="410" height="190" valign="top" align="center"> 
                <span class="nom_groupe"><?php echo $tableau[$i+1]["nom_groupe"]; ?></span> 
                <br><br> 
                <img src="images/<?php echo $tableau[$i+1]['img_groupe']; ?>"> 
                </td> 
                 
                <td background="images/cadre_06.gif" width="5" height="190"></td> 
              </tr> 
            </table> 
            <table width="420" cellpadding="0" cellspacing="0"> 
              <tr> 
                <td background="images/cadre_07.gif" width="5" height="5"></td> 
                <td background="images/cadre_08.gif" width="410" height="5"></td> 
                <td background="images/cadre_09.gif" width="5" height="5"></td> 
              </tr> 
            </table> 
         </td> 
	  </tr>
      </table>
	  
<?php $i++; } } } ?>


Merci
Modifié par bromlecornu (03 Oct 2007 - 17:03)
Je pense plus que cela doit etre dans se style. si je me trompe pas.

<? 
$sql = "SELECT num_groupe, nom_groupe, img_groupe FROM groupe Group By num_groupe";
$sql_exe = mysql_query($sql) or die('Erreur : ' . mysql_error());
$i=0;
while ($Tab = mysql_fetch_array($sql_exe)) {
	$tableau[$i]=$Tab;
	$i++;
}
	for($i=0;$i<count($tableau);$i++){
?>
	<br><table width="860" height="0" border="0" cellpadding="0" cellspacing="0">
	<tr>
      <td width="860" height="200" valign="top" align="center"> 
            <table width="420" cellpadding="0" cellspacing="0" border="0"> 
              <tr> 
                <td background="images/cadre_01.gif" width="5" height="5"></td> 
                <td background="images/cadre_02.gif" width="410" height="5"></td> 
                <td background="images/cadre_03.gif" width="5" height="5"></td> 
              </tr> 
            </table> 
            <table width="420" cellpadding="0" cellspacing="0"> 
              <tr> 
                <td background="images/cadre_04.gif" width="5" height="190"></td> 
                <td background="images/cadre_05.gif" width="410" height="190" valign="top" align="center"> 
                <span class="nom_groupe"><?php echo $tableau[$i]["nom_groupe"]; ?></span> 
                <br><br> 
                <img src="images/<?php echo $tableau[$i]['img_groupe']; ?>"> 
                </td>
                <td background="images/cadre_06.gif" width="5" height="190"></td> 
              </tr> 
            </table> 
            <table width="420" cellpadding="0" cellspacing="0"> 
              <tr> 
                <td background="images/cadre_07.gif" width="5" height="5"></td> 
                <td background="images/cadre_08.gif" width="410" height="5"></td> 
                <td background="images/cadre_09.gif" width="5" height="5"></td> 
              </tr> 
            </table> 
         </td> 
<?
		if(isset($tableau[$i+1])){
?>
      <td width="860" height="200" valign="top" align="center"> 
            <table width="420" cellpadding="0" cellspacing="0" border="0"> 
              <tr> 
                <td background="images/cadre_01.gif" width="5" height="5"></td> 
                <td background="images/cadre_02.gif" width="410" height="5"></td> 
                <td background="images/cadre_03.gif" width="5" height="5"></td> 
              </tr> 
            </table> 
            <table width="420" cellpadding="0" cellspacing="0"> 
              <tr> 
                <td background="images/cadre_04.gif" width="5" height="190"></td> 

                <td background="images/cadre_05.gif" width="410" height="190" valign="top" align="center"> 
                <span class="nom_groupe"><?php echo $tableau[$i+1]["nom_groupe"]; ?></span> 
                <br><br> 
                <img src="images/<?php echo $tableau[$i+1]['img_groupe']; ?>"> 
                </td> 
                <td background="images/cadre_06.gif" width="5" height="190"></td> 
              </tr> 
            </table> 
            <table width="420" cellpadding="0" cellspacing="0"> 
              <tr> 
                <td background="images/cadre_07.gif" width="5" height="5"></td> 
                <td background="images/cadre_08.gif" width="410" height="5"></td> 
                <td background="images/cadre_09.gif" width="5" height="5"></td> 
              </tr> 
            </table> 
         </td> 
	  </tr>
      </table>
<?php $i++; 
		}
		else{
			echo'
			</tr>
			</table>';
		}
	}?>