requete 3 colonnes ok mais decalage

Eléphant du PHP | 299 Messages

14 avr. 2012, 19:49

Salut a tous!

J' ai voulu essayer un morceau de code trouvé sur le net pour afficher une requete sur 3 colonnes et gagner du temps.

Ca marche assez bizarrement, l' affichage des données elles s' affichent bien mais souvent un décalage.

En l' occurence, la premiere colonne affiche une sorte de valign à "center" ou vertical-align en css a "middle".

Plutot etrange, voic la photo d' ensemble pour que vous voyez la 1ere colonne.


http://hpics.li/7825cc7

J' ai rejouté du coup au fur a mesure des balises de centrage tant en html qu' en css, mais ca ne change rien, voici mon code:
<?php
 $result = mysql_query('SELECT * FROM logi_cat ORDER BY cat ASC')or die (mysql_error());
// On choisit de faire trois colonnes
$NbCol=3;
// Il y a un total de NbTot enregistrements
$NbTot=mysql_num_rows($result);
// Il va falloir un certain nombre de lignes
$NbLigne=1+(int)($NbTot/$NbCol);
// Premier enregistrement
$Lig=0; // Pour savoir sur quelle ligne on est
// tant qu'il y a des fiches
echo '<table width="900" border="1" height="0" align="center" valign="top" cellpadding="0" cellspacing="0"><tr><td>';
while ($logi = mysql_fetch_array($result)) {
   ?>
   
   
   
    <table width="280" valign="top" border="0" align="center" cellpadding="0" cellspacing="0">
    		        <tr>
    		          <td height="40" align="left" valign="top" style="font-size:20px; color:#900; margin-top:0; vertical-align:top;"><img src="images/icones/<?php echo $logi['icone']; ?>" align="absmiddle" width="30" height="30" /><img src="images/header/blank.png" width="5" height="1" /><?php echo $logi['cat']; ?></td>
   		            </tr>
    		        <tr>
    		          <td align="left" valign="top">
    		            
    		            
    		            <table width="280" border="0" cellspacing="0" cellpadding="0">
    		              <?php
                $logi4 = mysql_query('SELECT * FROM logi_scat WHERE id_cat = "'.$logi['cat'].'" ORDER BY scat ASC')or die (mysql_error());
		   	    while ($logi3 = mysql_fetch_array($logi4))
		        {
				?>
    		              <tr><td height="25" valign="top"  style="margin-top:0; vertical-align:top;"><?php echo $logi3['scat']; ?></td></tr>
    		              <?php
				}
				?>
   		                </table>
   		              </td>
   		            </tr>
   		          </table>
    		      
    		      
    		      <br />
    		      <br />
                  
                  
                  
                  
                  <?php
   $Lig=$Lig+1;
   if($Lig==$NbLigne){echo "</td>
   <td valign=top>";$Lig=0;}
   // enregistrement suivant
}
echo "</td></tr></table>";
?> 
Merci d' avance, tout conseil est evidemment bon a prendre! :D

Eléphant du PHP | 299 Messages

14 avr. 2012, 21:07

Un petit up (tot je sais :lol: ) avant d' aller me coucher!

Merci d' avance!

ViPHP
ViPHP | 2287 Messages

15 avr. 2012, 19:25

Hello,

C'est quoi qui gêne, le décalage en haut de la colonne de gauche ?

Si oui c'est un problème d'HTML/CSS et l'idéal serait d'avoir un lien vers ta page pour constater le rendu et te proposer des solutions :)

Mais d'une manière générale, quand on prend du code alien "pour gagner du temps" et que finalement on n'en gagne pas (et qu'on se retrouve avec des problèmes qu'on ne comprend pas), ben vaut mieux changer d'approche...
if(!@work()){ Nespresso(); } else { what(); }
______________________________