質問編集履歴

2

誤字を修正いたしました。

2019/05/11 00:51

投稿

amaturePy
amaturePy

スコア131

test CHANGED
File without changes
test CHANGED
@@ -10,9 +10,7 @@
10
10
 
11
11
  ```PHP
12
12
 
13
- コード
14
-
15
- !DOCTYPE html>
13
+ <!DOCTYPE html>
16
14
 
17
15
  <html>
18
16
 

1

マークアップにコードを入れ直しました。申し訳ございませんでした。

2019/05/11 00:51

投稿

amaturePy
amaturePy

スコア131

test CHANGED
File without changes
test CHANGED
@@ -8,11 +8,11 @@
8
8
 
9
9
 
10
10
 
11
- ```ここに言語を入力
11
+ ```PHP
12
12
 
13
13
  コード
14
14
 
15
- ```<!DOCTYPE html>
15
+ !DOCTYPE html>
16
16
 
17
17
  <html>
18
18
 
@@ -38,7 +38,7 @@
38
38
 
39
39
  $weekday = array( "Sunday", "Monday", "Thuseday", "Wednesday", "Thursday", "Friday", "Saturday" );
40
40
 
41
- // 1日の曜日を数値で取得
41
+
42
42
 
43
43
  $fir_weekday = date( "w", mktime( 0, 0, 0, $now_month, 1 , $now_year ) );
44
44
 
@@ -52,180 +52,184 @@
52
52
 
53
53
  .$now_month."/".$now_year."
54
54
 
55
- </caption>\n";///////////////caption
55
+ </caption>\n";////////////////////////caption
56
+
57
+
58
+
56
-
59
+ echo "<tr>\n";
60
+
61
+
62
+
57
-
63
+ $i = 0; // カウント値リセット
64
+
65
+ while( $i <= 6 ){ // 曜日分ループ
66
+
67
+
68
+
69
+ /////////////////////////////////////style sheet
70
+
71
+ if( $i == 0 ){ // 日曜日の文字色
72
+
73
+ $style = "#C30";
74
+
75
+ }
76
+
77
+ else if( $i == 6 ){ // 土曜日の文字色
78
+
79
+ $style = "#03C";
80
+
81
+ }
82
+
83
+ else{ // 月曜~金曜日の文字色
84
+
85
+ $style = "black";
86
+
87
+ }
88
+
89
+ echo "\t<th style=\"color:".$style."\">".$weekday[$i]."</th>\n";
90
+
91
+ $i ++; //カウント値+1
92
+
93
+ }
94
+
95
+ /////////////////////////////////////end of style sheet
96
+
97
+ // 行の変更
98
+
99
+ echo "</tr>\n";
58
100
 
59
101
  echo "<tr>\n";
60
102
 
61
103
 
62
104
 
63
- $i = 0; // カウント値リセット
105
+ $i = 0;
64
-
106
+
65
- while( $i <= 6 ){ // 曜日分ループ
107
+ while( $i != $fir_weekday ){
108
+
66
-
109
+ echo "\t<td>&nbsp;</td>\n";
110
+
67
-
111
+ $i ++;
112
+
68
-
113
+ }
114
+
115
+
116
+
117
+ // 今月の日付が存在している間ループする
118
+
119
+ for( $day=1; checkdate( $now_month, $day, $now_year ); $day++ ){
120
+
121
+
122
+
123
+ //曜日の最後まできたらカウント値(曜日カウンター)を戻して行を変える
124
+
125
+ if( $i > 6 ){
126
+
127
+ $i = 0;
128
+
129
+ echo "</tr>\n";
130
+
131
+ echo "<tr>\n";
132
+
133
+ }
134
+
135
+
136
+
69
- /////////////////////////////////////style sheet
137
+ ///////////////////////////////////////style sheet
70
-
138
+
71
- if( $i == 0 ){ // 日曜日の文字色
139
+ if( $i == 0 ){///the color of sunday
72
140
 
73
141
  $style = "#C30";
74
142
 
75
- }
143
+
76
-
144
+
77
- else if( $i == 6 ){ // 土曜日の文字色
145
+ } else if( $i == 6 ){ //the color of saturday
78
146
 
79
147
  $style = "#03C";
80
148
 
81
- }
149
+
82
-
150
+
83
- else{ // 月曜~金曜日の文字色
151
+ } else { //the color of monday to friday
84
152
 
85
153
  $style = "black";
86
154
 
87
155
  }
88
156
 
157
+
158
+
89
- echo "\t<th style=\"color:".$style."\">".$weekday[$i]."</th>\n";
159
+ // if it is today , it gets color
90
-
160
+
91
- $i ++; //カウント値+1
161
+ if( $day == $now_day ){
162
+
92
-
163
+ $style = $style."; background:silver";
164
+
93
- }
165
+ }
94
-
166
+
95
- /////////////////////////////////////end of style sheet
167
+ //////////////////////////////////////end of style sheet
96
-
168
+
169
+
170
+
97
- // 変更
171
+ // 日付セル作成とスタイルシート挿入
172
+
173
+ echo "\t<td style=\"color:".$style.";\">".$day."</td>\n";
174
+
175
+
176
+
177
+ $i++; //カウント値(曜日カウンター)+1
178
+
179
+ }
180
+
181
+
182
+
183
+ while( $i < 7 ){ //残りの曜日分空白(&nbsp;)で埋める
184
+
185
+ echo "\t<td>&nbsp;</td>\n";
186
+
187
+ $i++;
188
+
189
+ }
98
190
 
99
191
  echo "</tr>\n";
100
192
 
101
- echo "<tr>\n";
102
-
103
-
104
-
105
- $i = 0;
106
-
107
- while( $i != $fir_weekday ){
108
-
109
- echo "\t<td>&nbsp;</td>\n";
110
-
111
- $i ++;
112
-
113
- }
114
-
115
-
116
-
117
- // 今月の日付が存在している間ループする
118
-
119
- for( $day=1; checkdate( $now_month, $day, $now_year ); $day++ ){
120
-
121
-
122
-
123
- //曜日の最後まできたらカウント値(曜日カウンター)を戻して行を変える
124
-
125
- if( $i > 6 ){
126
-
127
- $i = 0;
128
-
129
- echo "</tr>\n";
130
-
131
- echo "<tr>\n";
132
-
133
- }
134
-
135
-
136
-
137
- ///////////////////////////////////////style sheet
138
-
139
- if( $i == 0 ){///the color of sunday
140
-
141
- $style = "#C30";
142
-
143
-
144
-
145
- } else if( $i == 6 ){ //the color of saturday
146
-
147
- $style = "#03C";
148
-
149
-
150
-
151
- } else { //the color of monday to friday
152
-
153
- $style = "black";
154
-
155
- }
156
-
157
-
158
-
159
- // if it is today , it gets color
160
-
161
- if( $day == $now_day ){
162
-
163
- $style = $style."; background:silver";
164
-
165
- }
166
-
167
- //////////////////////////////////////end of style sheet
168
-
169
-
170
-
171
- // 日付セル作成とスタイルシートの挿入
172
-
173
- echo "\t<td style=\"color:".$style.";\">".$day."</td>\n";
174
-
175
-
176
-
177
- $i++; //カウント値(曜日カウンター)+1
178
-
179
- }
180
-
181
-
182
-
183
- while( $i < 7 ){ //残りの曜日分空白(&nbsp;)で埋める
184
-
185
- echo "\t<td>&nbsp;</td>\n";
186
-
187
- $i++;
188
-
189
- }
190
-
191
- echo "</tr>\n";
192
-
193
193
  echo "</table>\n";
194
194
 
195
195
 
196
196
 
197
197
  ///////////////////////////////////////////////////////previous and next month
198
198
 
199
- for($now_month=0;$now_month<=12;$now_month++){
200
-
201
- break;
202
-
203
- }
204
-
205
- ?>
199
+ ?>
200
+
201
+
202
+
206
-
203
+ <?php
204
+
207
- <form action="previous_month.php" method="POST">
205
+ $ym = (isset($_GET["ym"]))? $_GET["ym"] : date("Ym");
208
-
209
- <input type="submit" name="previous_month" value="PreviousMonth">
206
+
210
-
207
+
208
+
211
- <input type="submit" name="next_month" value="NextMonth">
209
+ $lastmonth = date("Ym",strtotime($ym."01"." -1 month "));
210
+
212
-
211
+ $nextmonth = date("Ym",strtotime($ym."01"." +1 month "));
212
+
213
+
214
+
215
+ echo '<a href="ex5-2.php?ym='.$lastmonth.'">Last month</a>';
216
+
213
- </form>
217
+ echo "<br>";
218
+
214
-
219
+ echo '<a href="ex5-2.php?ym='.$nextmonth.'">Next month</a>';
220
+
221
+
222
+
215
-
223
+ $this_month_days = date("t",strtotime($ym."01"));//当月の日数を取得。
224
+
216
-
225
+ ?>
217
-
218
-
219
-
220
-
221
-
222
-
226
+
227
+
228
+
223
- </body>
229
+ </body>
224
-
230
+
225
- </html>
231
+ </html>
226
-
227
-
228
-
229
- コード
232
+
233
+
230
234
 
231
235
  ```