Sos debutante , affichage d'un tableau

bilane Messages postés 13 Statut Membre -  
 Corni -
Je cherche à afficher dans un tableau de 6 lignes et 5 colonnes, les membres d’année de parution d’un journal, la période est de 1977 à nos jours (2006), comme ceci :

2006 2005 2004 2003 2002
2001 2000 1999 1998 1997
----

Seulement voilà un petit problème: Les informations se placent toutes sur une même colonne, déformant ainsi le design de la page.

Je voudrai savoir comment faire pour les afficher correctement.

le code:

<?php

echo '<center><h4>Recherche par Année </br></br></br></h4></center>';
$an=gmdate('Y');
$i=1977; $j=0; $k=0;
?>
<table border='1'>
<?php
$td = '';
WHILE ($an >= $i){
if ($j > 4) $j = 0; {echo "<tr>";
if ($K > 5) $k = 0;
{echo "<td>\r\n <a href=rechercheannee5.php?annee=$an>$an</a></td>\r\n"; $td = ''; $k++; }
echo "</tr>";
$j++;}
$an--;
Echo "</table>" ;

} ?>

Merci de votre aide.

2 réponses

  1. elghafoud Messages postés 129 Statut Membre 18
     
    j'ai completement changé ton script ::: voici ma version,,, a toi de voir combien de colonnes tu veux et quelle date commance le compteur! !!

    <?php
    echo '<center><h4>Recherche par Année </br></br></br></h4></center>';

    $year = date("Y");
    $year_end = 1977;
    $nb_col = 5;

    echo '<table width="300px" border="1">';
    while ($year > $year_end) {
    if ($i==$nb_col) {
    echo "</tr>";
    $i=0;
    }
    if ($i==0) {
    echo "<tr>";
    }
    echo "<td>$year</td>";
    $i++;
    $year--;
    }

    if ($i>0 && $i<$nb_col) {
    while ($i<$nb_col) {
    echo "<td> </td>";
    $i++;
    }
    echo "</tr>";
    }
    echo '</table>';

    ?>
    0
  2. Corni
     
    Voici une autre possiblité assez proche:

    <?php
    $nbCol = 5;
    $startYear = 1997;
    $endYear = date('Y');
    
    print("<table>\n");
    
    $year = $startYear;
    while ($year <= $endYear) {
        $colCount = 0;
        print("<tr>");
        while ($colCount <= $nbCol) {
            if ($year > $endYear) {
                print("<td> </td>\n");
            } else {
                print("<td>".$year."</td>\n");
            }
            $colCount++;
            $year++;
        }
        print("</tr>\n");
    }
    print("</table>");
    
    0