Liste SQL

Résolu
Bonjour,

Voila, j'ai créer une request SQL pour afficher une liste dans un tableau en PHP:

<?php
$result = mysql_query("SELECT * FROM 1HPS20100711 ORDER by '$t'");
while ($row = mysql_fetch_array($result)){
echo '<tr class="list">
<td align="center" width="10%">#</td>
<td align="center" width="40%">'.$row[shNom].', '.$row[shPnom].'</td>
<td width="10%" align="center"><img src="/images/pays/'.$row[shPays].'.gif" border="0" height="40%" width="40%"></td>
<td align="center" width="10%">'.$row[shDiv];
if($row[shFac] == "MAJ"){echo '+';}
echo '</td>
<td align="center" width="10%">'.$row[shCat].'</td>
<td align="center" width="20%">.</td>
</tr>';}
?>

Par contre, je voudrais qu'une ligne sur deux change de couleur.

Comment peut on faire?

Merci d'avance
Eric
Configuration: Windows XP
Firefox 3.5.5

6 réponses

  1. $i = 0 ;
    while(){
    ?>
    <tr style="background-color:<?php ($i%2==0?echo "red" :echo "blue"); ?> ">
    <?php
    $i++
    }

    (condition?si vrai:si faut)
    1. Merci pour ta reponse rapide,

      mais le bout de code que tu m'as donné, je le mets où dans le mien.

      La question peut peut etre paraitre con, mais le langage SQL est nouveau pour moi.

      Merci
      1. <?php
        $result = mysql_query("SELECT * FROM 1HPS20100711 ORDER by '$t'");
        $i = 0;
        while ($row = mysql_fetch_array($result)) {
        	$color = (($i % 2) == 0) ? 'red' : 'green';
        	echo '<tr class="list" style="background:'.$color.';">'."\n".
        	"\t".'<td align="center" width="10%">#</td>'."\n".
        	"\t".'<td align="center" width="40%">'.$row[shNom].', '.$row[shPnom].'</td>'."\n".
        	"\t".'<td width="10%" align="center"><img src="/images/pays/'.$row[shPays].'.gif" border="0" height="40%" width="40%"></td>'."\n".
        	"\t".'<td align="center" width="10%">'.$row[shDiv]; if($row[shFac] == "MAJ"){echo '+';} echo '</td>'."\n".
        	"\t".'<td align="center" width="10%">'.$row[shCat].'</td>'."\n".
        	"\t".'<td align="center" width="20%">.</td>'."\n".
        	'</tr>'."\n";
        	$i++;
        }
        ?>
        1. Desole, mais je ne viens de test vos conseilles que maintenant.

          Ca marche

          Merci encore