Alterner les couleurs d'un tableau

Salut,
Je génère un tableau à partir de ma bae de donnée MySQL par la commande :
while ($ligne = mysql_fetch_array($requete)) {
print "<........$ligne[ID_champ1]....>" avec toutes les balises tr et td nécessaires.

Ca marche bien mais je voudrais que chaque ligne du tableau prenne une couleur de fond différente ou au moins qu'il y ait alternance entre 2 couleurs.

Merci de votre aide...

2 réponses

  1. Modérateur
    Hello,
    Inspire-toi de ceci
    <?php
    $colors = array("#FFFF55", "#55FFFF");
    $header = "<html><body><table>";
    $foot="</table></body></html>";
    $data=array("pomme"=>"vert", "citron"=>"jaune", "abrticot"=> "orange",
    "cerise"=> "noir");
    print("$header\n");
    $flag=0;
    foreach($data as $key=>$value)
    {
    $row = sprintf("<tr bgcolor=%s><td>%s</td><td>%s</td></tr>\n",
    $colors[$flag], $key, $value);
    print($row);
    $flag = 1-$flag;
    }
    print($foot);
    ?>
    Johan

    The software said "Requires Windows98, Win2000, or better,
    So I installed Unix.
    -1
    1. Modérateur
      Pour être plus puriste:
      <?php
      $colors = array("#FFFF55", "#55FFFF");
      $header = "<html><body><table>";
      $foot="</table></body></html>";
      $data=array("pomme"=>"vert", "citron"=>"jaune", "abrticot"=> "orange",
      "cerise"=> "noir");
      print("$header\n");
      $flag=0;
      foreach($data as $key=>$value)
      {
      $row = sprintf("<tr bgcolor='%s'><td>%s</td><td>%s</td></tr>\n",
      $colors[$flag], $key, $value);
      print($row);
      $flag = 1-$flag;
      }
      print($foot);
      ?>
      Johan
      The software said "Requires Windows98, Win2000, or better,
      So I installed Unix.
      -1