Précédent   Forum des professionnels en informatique > PHP > Langage
Langage Forum sur le langage PHP, la POO, les conventions, la sécurité, etc. Avant de poster : FAQ Langage, toutes les FAQ PHP, cours langage et sources PHP
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 17/07/2008, 12h39   #1
Membre du Club
 
Inscription : décembre 2007
Messages : 121
Détails du profil
Informations forums :
Inscription : décembre 2007
Messages : 121
Points : 40
Points : 40
Par défaut [Dates] Aide pour calendrier

J'ai cherché un script de calendrier le plus simple possible afin le comprendre correctement. J'ai changé quelque petite chose. Le voila:

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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
 
<?php 
 
//This gets today's date 
$date =time ();
 
//This puts the day, month, and year in seperate variables 
$day = date('d', $date);
$month = date('m', $date);
$year = date('Y', $date);
 
//Here we generate the first day of the month 
$first_day = mktime(0,0,0,$month, 1, $year);
 
 
//This gets us the month name 
$title = date('n', $first_day);
 
 
 
 
if ($title == 1)
{
$title = 'Janvier';
}
elseif ($title == 2)
{
$title = 'Février';
}
elseif ($title == 3)
{
$title = 'Mars';
}
elseif ($title == 4)
{
$title = 'Avril';
}
elseif ($title == 5)
{
$title = 'Mai';
}
elseif ($title == 6)
{
$title = 'Juin';
}
elseif ($title == 7)
{
$title = 'Juillet';
}
elseif ($title == 8)
{
$title = 'Aout';
}
elseif ($title == 9)
{
$title = 'Septembre';
}
elseif ($title == 10)
{
$title = 'octobre';
}
elseif ($title == 11)
{
$title = 'Novembre';
}
else
{
$title = 'Décembre';
}
 
 
 
 
 
 
 
 
 
 
 
 
//Here we find out what day of the week the first day of the month falls on 
$day_of_week = date('D', $first_day);
 
 
//Once we know what day of the week it falls on, we know how many blank days occure before it. If the first day of the week is a Sunday then it would be zero
switch($day_of_week)
{ 
case "Sun": $blank = 0; break; 
case "Mon": $blank = 1; break; 
case "Tue": $blank = 2; break; 
case "Wed": $blank = 3; break; 
case "Thu": $blank = 4; break; 
case "Fri": $blank = 5; break; 
case "Sat": $blank = 6; break; 
}
 
//We then determine how many days are in the current month
$days_in_month = cal_days_in_month(0, $month, $year);
 
 
 
 
 
 
 
//Here we start building the table heads 
echo "<table border=0 width=350 height=300>";
echo "<tr><th colspan=7> $title $year </th></tr>";
echo "<tr><td width=50 align=center>Di</td><td width=50 align=center>Lu</td><td width=50 align=center>Ma</td><td width=50 align=center>Me</td><td width=50 align=center>Je</td><td width=50 align=center>Ve</td><td width=50 align=center>Sa</td></tr>";
 
//This counts the days in the week, up to 7
$day_count = 1;
 
echo "<tr>";
//first we take care of those blank days
while ( $blank > 0 ) 
{ 
echo "<td></td>"; 
$blank = $blank-1; 
$day_count++;
} 
 
 
 
 
 
 
 
//sets the first day of the month to 1 
$day_num = 1;
 
//count up the days, untill we've done all of them in the month
while ( $day_num <= $days_in_month ) 
{ 
echo "<td align=\"center\"> $day_num </td>"; 
$day_num++; 
$day_count++;
 
//Make sure we start a new row every week
if ($day_count > 7)
{
echo "</tr><tr>";
$day_count = 1;
}
} 
 
 
 
 
//Finaly we finish out the table with some blank details if needed
while ( $day_count >1 && $day_count <=7 ) 
{ 
echo "<td> </td>"; 
$day_count++; 
} 
 
echo "</tr></table>"; 
 
 
 
?>
Tout cela est affiché dans une div.

Ma question est la suivante: comment affiché le jour actuel dans une autre couleur?

Comment affiché dans d'autre div supperposé (ca c'est je sais le faire avec le css) les autres mois de l'année ?
lelapinrusse est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 17/07/2008, 15h50   #2
Candidat au titre de Membre du Club
 
Inscription : juin 2008
Messages : 19
Détails du profil
Informations forums :
Inscription : juin 2008
Messages : 19
Points : 10
Points : 10
salut,
je crois qu'il suffit de faire un test si la date à afficher est égale à celle d'aujourd'hui.voila un un test qui peut résoudre ton problème j'espère:

Code :
1
2
3
4
5
6
 
 if( $day_num  == date("j") && $month == date("n") && $year == date("Y"))
//si tu veut afficher la date d'aujourd'hui en rouge
{echo "<td align=\"center\"><font color='#FF0000'> $day_num</font> </td>";}
else
{echo "<td align=\"center\"> $day_num</td>"; }
hamta est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 22/07/2008, 18h25   #3
Membre du Club
 
Inscription : décembre 2007
Messages : 121
Détails du profil
Informations forums :
Inscription : décembre 2007
Messages : 121
Points : 40
Points : 40
merci, ca fonctionne très bien pour le jour.

Quelqu'un aurait une idée pour les mois de l'année.

Je pensais à récupérer le mois actuel et de faire + 1 au mois actuel jusqu'à 12 et - 1 jusqu' 1 et de faire une boucle avec tout ca mais je vois pas comment y arriver...
lelapinrusse 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 21h28.


 
 
 
 
Partenaires

Hébergement Web