IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Langage PHP Discussion :

Affichage de tous les mois d'un calendrier


Sujet :

Langage PHP

  1. #1
    Membre du Club
    Inscrit en
    Avril 2008
    Messages
    141
    Détails du profil
    Informations forums :
    Inscription : Avril 2008
    Messages : 141
    Points : 53
    Points
    53
    Par défaut Affichage de tous les mois d'un calendrier
    Bonjour,je souhaite afficher un calendrier dont figureront seulement tous les mois de l'année . en 2 lignes et 6 colonnes(de janvier à juin la 1re et de juillet à decembre la deuxième.).

    Je suis parti d'un calendrier normal qui affichait les jours par date.
    Aidez moi svp!!!

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
     
    <?php
    //Creating general vars
    $year = date("Y");
    if(!isset($_GET['month'])) $monthnb = date("n");
    else {
        $monthnb = $_GET['month'];
        $year = $_GET['year'];
        if($monthnb <= 0) {
            $monthnb = 12;
            $year = $year - 1;
        }
        elseif($monthnb > 12) {
            $monthnb = 1;
            $year = $year + 1;
        }
    }
    $day = date("w");
    $nbdays = date("t", mktime(0,0,0,$monthnb,1,$year));
    $firstday = date("w",mktime(0,0,0,$monthnb,1,$year));
     
    //Replace the number of the day by its french name
    $daytab[1] = 'Janvier';
    $daytab[2] = 'Fevrier';
    $daytab[3] = 'Mars';
    $daytab[4] = 'Avril';
    $daytab[5] = 'Mai';
    $daytab[6] = 'Juin';
    $daytab[7] = 'Juillet';
    $daytab[8] = 'Aout';
    $daytab[9] = 'Septembre';
    $daytab[10] = 'Octobre';
    $daytab[11] = 'Novembre';
    $daytab[12] = 'Decembre';
     
    //Build the calendar table
    $calendar = array();
    $z = (int)$firstday;
    if($z == 0) $z =7;
    for($i = 1; $i <= ($nbdays/5); $i++){
        for($j = 1; $j <= 7 && $j-$z+1+(($i*7)-7) <= $nbdays; $j++){
            if($j < $z && ($j-$z+1+(($i*7)-7)) <= 0){
                    $calendar[$i][$j] = null;
            }
            else {
                $calendar[$i][$j] = $j-$z+1+(($i*7)-7);            
            }
        }
    }
     
    //Replace the number of the month by its french name
    switch($monthnb) {
        case 1: $month = 'Janvier'; break;
        case 2: $month = 'Fevrier'; break;
        case 3: $month = 'Mars'; break;
        case 4: $month = 'Avril'; break;
        case 5: $month = 'Mai'; break;
        case 6: $month = 'Juin'; break;
        case 7: $month = 'Juillet'; break;
        case 8: $month = 'Août'; break;
        case 9: $month = 'Septembre';    break;
        case 10: $month = 'Octobre'; break;
        case 11:    $month = 'Novembre';    break;
        case 12:    $month = 'Décembre';    break;
    }
    ?>
    <div id="calendrier">
        <table>
            <tr>
                <th><span class="linkcal"><a href="ajaxaffiche?month=<?php echo $year - 1; ?>&year=<?php echo $year; ?>"><<</a></span></th>
                <th colspan="5" class="headcal"><?php echo($year);  ?></th>
                <th><span class="linkcal"><a href="ajaxaffiche?month=<?php echo $year + 1; ?>&year=<?php echo $year; ?>">>></a></span></th>
                <th><a href="#"><img  id="calendrier" src="<?php echo $this->baseUrl();?>/images/icones_js_calendrier/annee.jpg"></a></th>      
            </tr>
            <?php
                echo('<tr>');
                for($i = 1; $i <= 12; $i++){
                    echo('<th>'.$daytab[$i].'</th>');
                }
                echo('</tr>');
                for($i = 1; $i <= count($calendar); $i++) {
                    echo('<tr>');
                        if($monthnb == date("n") && $year == date("Y")) echo('<th class="current" style="width:107px;height:50px;background-color:silver;"><div style="width:40px;height:20px;background-color:white;float:left;margin-top:-20px;">'.$calendar[$i].'<div></th>');
                        else echo('<th style="width:107px;height:50px;background-color:silver;"><div style="width:40px;height:20px;background-color:white;float:left;margin-top:-20px;">'.$calendar[$i].'</div></th>');
     
                    echo('</tr>');
                }
            ?>
        </table>
    </div>

  2. #2
    Modérateur
    Avatar de sabotage
    Homme Profil pro
    Inscrit en
    Juillet 2005
    Messages
    29 208
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations forums :
    Inscription : Juillet 2005
    Messages : 29 208
    Points : 44 155
    Points
    44 155
    Par défaut
    Pourquoi faire simple ?

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    <?php
    $tblMois[1] = 'Janvier';
    $tblMois[2] = 'Fevrier';
    $tblMois[3] = 'Mars';
    $tblMois[4] = 'Avril';
    $tblMois[5] = 'Mai';
    $tblMois[6] = 'Juin';
    $tblMois[7] = 'Juillet';
    $tblMois[8] = 'Aout';
    $tblMois[9] = 'Septembre';
    $tblMois[10] = 'Octobre';
    $tblMois[11] = 'Novembre';
    $tblMois[12] = 'Decembre';
     
    echo '<table>
    		<tr>';
    foreach ($tblMois as $n=>$mois) {
    	if ($n == 7) { echo '</tr><tr>'; }
    	echo '<td>' . $mois . '</td>';
    }
    echo '</tr>
    </table>';

  3. #3
    Membre du Club
    Inscrit en
    Avril 2008
    Messages
    141
    Détails du profil
    Informations forums :
    Inscription : Avril 2008
    Messages : 141
    Points : 53
    Points
    53
    Par défaut
    Ah merci c'est super c'est bon mais par contre comment le gérer l'année juste au dessus et pouvoir passer de l'année d'avant à l'année suivante si on veut

  4. #4
    Membre expert Avatar de RunCodePhp
    Profil pro
    Inscrit en
    Janvier 2010
    Messages
    2 962
    Détails du profil
    Informations personnelles :
    Localisation : Réunion

    Informations forums :
    Inscription : Janvier 2010
    Messages : 2 962
    Points : 3 947
    Points
    3 947
    Par défaut
    Salut

    par contre comment le gérer l'année juste au dessus et pouvoir passer de l'année d'avant à l'année suivante si on veut
    Le même principe que tous les sites Web : un lien ou un formulaire
    Suffit de rajouter/transmettre l'info en paramètre (comme l'année par exemple).

    Mais un calendrier c'est pas si simple, surtout si on souhaite mettre les jours, les semaines, n'en parlons même pas des jours fériés, et dans des langues différentes.
    Il existe des calendriers en Javascipt ou en Php qui sont plus ou moins évolués.
    En adopter un ou t'en inspirer peut être fort utile.

  5. #5
    Membre du Club
    Inscrit en
    Avril 2008
    Messages
    141
    Détails du profil
    Informations forums :
    Inscription : Avril 2008
    Messages : 141
    Points : 53
    Points
    53
    Par défaut
    Voilà ce que j'ai essayé de faire en partant d'un calendrier
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    <?php
    //Creating general vars
    $year = date("Y");
    //if(!isset($_GET['month'])) $monthnb = date("n");
    //else {
    //    $monthnb = $_GET['month'];
    //    $year = $_GET['year'];
    //    if($monthnb <= 0) {
    //        $monthnb = 12;
    //        $year = $year - 1;
    //    }
    //    elseif($monthnb > 12) {
    //        $monthnb = 1;
    //        $year = $year + 1;
    //    }
    //}
     
    $tblMois[1] = 'Janvier';
    $tblMois[2] = 'Fevrier';
    $tblMois[3] = 'Mars';
    $tblMois[4] = 'Avril';
    $tblMois[5] = 'Mai';
    $tblMois[6] = 'Juin';
    $tblMois[7] = 'Juillet';
    $tblMois[8] = 'Aout';
    $tblMois[9] = 'Septembre';
    $tblMois[10] = 'Octobre';
    $tblMois[11] = 'Novembre';
    $tblMois[12] = 'Decembre';
    ?>
     
    <?php 
    echo '<table>
            <tr>';
    ?>
      <th><span class="linkcal"><a href="ajaxaffiche?year=<?php echo $year - 1; ?>"><<</a></span></th>
                <th colspan="5" class="headcal"><?php echo($year);  ?></th>
                <th><span class="linkcal"><a href="ajaxaffiche?year=<?php echo $year + 1; ?>">>></a></span></th>
                <th><a href="#"><img  id="calendrier" src="<?php echo $this->baseUrl();?>/images/icones_js_calendrier/annee.jpg"></a></th>      
     <?php        
    echo  '</tr>
    		<tr>';
    foreach ($tblMois as $n=>$mois) {
    	if ($n == 7) { echo '</tr><tr>'; }
    	echo '<td style="width:110px;height:50px;background-color:silver;">' . $mois . '</td>';
    }
    echo '</table>';
    ?>

Discussions similaires

  1. Affichage de tous les mois courbes
    Par paola2014 dans le forum SSRS
    Réponses: 3
    Dernier message: 11/09/2014, 16h44
  2. [2008R2] Histogramme - Affichage de tous les mois
    Par Melow57 dans le forum SSRS
    Réponses: 1
    Dernier message: 23/06/2014, 11h55
  3. Affichage de tous les mois
    Par redoran dans le forum Langage SQL
    Réponses: 30
    Dernier message: 07/05/2012, 16h37
  4. [Designer V5-V6] Afficher tous les mois du calendrier
    Par San_d dans le forum Débuter
    Réponses: 5
    Dernier message: 28/03/2009, 22h10
  5. Réponses: 4
    Dernier message: 25/06/2008, 14h57

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo