Précédent   Forum des professionnels en informatique > PHP > Langage > Débuter
Débuter Forum d'entraide pour débuter en PHP. Avant de poster -> Cours PHP, FAQ PHP, Outils PHP, etc.
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 03/03/2011, 11h56   #1
Membre à l'essai
 
Inscription : avril 2008
Messages : 140
Détails du profil
Informations forums :
Inscription : avril 2008
Messages : 140
Points : 21
Points : 21
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 :
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>
sajodia est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 03/03/2011, 12h08   #2
Modérateur
 
Avatar de sabotage
 
Homme Vincent
Inscription : juillet 2005
Messages : 14 929
Détails du profil
Informations personnelles :
Nom : Homme Vincent

Informations forums :
Inscription : juillet 2005
Messages : 14 929
Points : 16 381
Points : 16 381
Pourquoi faire simple ?

Code :
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>';
sabotage est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 03/03/2011, 12h14   #3
Membre à l'essai
 
Inscription : avril 2008
Messages : 140
Détails du profil
Informations forums :
Inscription : avril 2008
Messages : 140
Points : 21
Points : 21
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
sajodia est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 03/03/2011, 12h32   #4
Expert Confirmé
 
Avatar de RunCodePhp
 
Inscription : janvier 2010
Messages : 2 707
Détails du profil
Informations personnelles :
Localisation : Réunion

Informations forums :
Inscription : janvier 2010
Messages : 2 707
Points : 3 277
Points : 3 277
Salut

Citation:
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.
__________________
Win XP | WampServer 2.2d | Apache 2.2.21 | Php 5.3.10 | MySQL 5.5.20
Si debugger, c'est supprimer des bugs, alors programmer ne peut être que les ajouter [Edsger Dijkstra]
RunCodePhp est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 03/03/2011, 14h58   #5
Membre à l'essai
 
Inscription : avril 2008
Messages : 140
Détails du profil
Informations forums :
Inscription : avril 2008
Messages : 140
Points : 21
Points : 21
Voilà ce que j'ai essayé de faire en partant d'un calendrier
Code :
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>';
?>
sajodia est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 15h25.


 
 
 
 
Partenaires

Hébergement Web