質問するログイン新規登録

質問編集履歴

3

誤字を修正しました

2019/10/24 05:04

投稿

kenichi_myk
kenichi_myk

スコア14

title CHANGED
File without changes
body CHANGED
@@ -12,7 +12,7 @@
12
12
  <?php
13
13
  require './data.php';
14
14
 
15
- $base_url = 'http://****/calender_test/';
15
+ $base_url = 'http://****/calendar_test/';
16
16
 
17
17
  function funcIsAjax(){
18
18
  if(isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest')

2

同じソースを記載していた為

2019/10/24 05:04

投稿

kenichi_myk
kenichi_myk

スコア14

title CHANGED
File without changes
body CHANGED
@@ -102,101 +102,7 @@
102
102
 
103
103
  ?>
104
104
  ```
105
- ```php
106
- <?php
107
- require './data.php';
108
105
 
109
- $base_url = 'http://******/****/calender_test/';
110
-
111
- function funcIsAjax(){
112
- if(isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest')
113
- return true;
114
-
115
- return false;
116
- }
117
-
118
- if(funcIsAjax()) header("Content-type: text/plain; charset=UTF-8");
119
- else {header("Location: {$base_url}"); exit;}
120
-
121
- date_default_timezone_set('Asia/Tokyo'); //タイムゾーンの設定
122
-
123
- $today = $_POST;
124
- extract($today);
125
-
126
- $thisMonth = new DateTime($today);
127
- $dt = clone $thisMonth;
128
- $prev = $dt->modify('-1 month')->format('Y-m');
129
- $dt = clone $thisMonth;
130
- $next = $dt->modify('+1 month')->format('Y-m');
131
-
132
- $yearMonth = $thisMonth->format('Y F');
133
- $month = $thisMonth->format('Y-m');
134
-
135
- // カレンダー表示
136
- // 前月表示
137
- $tr = '<div class="cal_tr">';
138
- $tail = null;
139
- //前月の最終日を習得
140
- $lastDayOfPrevMonth = new DateTime('last day of ' . $yearMonth . ' -1 month');
141
- while ($lastDayOfPrevMonth->format('N') < 7) {
142
- $tail = sprintf('<div></div>', $lastDayOfPrevMonth->format('d')) . $tail;
143
- $tail = sprintf('<div class="cal cal_td empty"><div class="cal_body"></div></div>', $lastDayOfPrevMonth->format('d')) . $tail;
144
- $lastDayOfPrevMonth->sub(new DateInterval('P1D'));
145
- $prevmanth = $lastDayOfPrevMonth->format('Y-m');
146
- }
147
-
148
- // 当月表示
149
- $body = null;
150
- $period = new DatePeriod (
151
- new DateTime('first day of' . $yearMonth),
152
- new DateInterval('P1D'),
153
- new DateTime('first day of' . $yearMonth . '+1 month')
154
- );
155
-
156
- $today = new DateTime('today');
157
- foreach ($period as $day) {
158
- if ($day->format('N') === '1'){
159
- $body .= '</div></div>';
160
- $body .= '<div class="cal_tr">';
161
- }
162
- $days = $day->format('Y-m-d');
163
-
164
- foreach($holiday as $key) {
165
- $id = $key['id'];
166
- $user = $key['account_id'];
167
- $kana = $key['account_kana'];
168
- $from = $key['datetime_from'];
169
- $to = $key['datetime_from'];
170
- $type = $key['holiday_type'];
171
- }
172
- if($from == $days) {
173
- $todayClass = ($day->format('Y-m-d') === $today->format('Y-m-d')) ? 'today' : '';
174
- $body .= sprintf('<div class="cal cal_td" data-date="' . $days . '"><div class="cal_date day_%d %s">%d</div><div class="cal_plan"></div><div class="cal_body"><div class="area_btn" data-user="' . $user . ' data-user="' . $kana . ' "data-from="' . $from . '" data-to="' . $to . '" data-type="' . $type . '">' . $type . '/' . ' ' .$user .'</div></div></div>', $day->format('w'), $todayClass, $day->format('d'));
175
- } else {
176
- $todayClass = ($day->format('Y-m-d') === $today->format('Y-m-d')) ? 'today' : '';
177
- $body .= sprintf('<div class="cal cal_td" data-date="' . $days . '"><div class="cal_date day_%d %s">%d</div><div class="cal_plan"></div><div class="cal_body"></div></div>', $day->format('w'), $todayClass, $day->format('d'));
178
-
179
- }
180
- }
181
-
182
- // 次月表示
183
- $head = null;
184
- $firstDayOfNextMonth = new DateTime('first day of' . $yearMonth . '+1 month');
185
- // var_dump($firstDayOfNextMonth->format('N'));
186
- while($firstDayOfNextMonth->format('N') > 1) {
187
- $head .= '<div class="cal cal_td empty">' . $firstDayOfNextMonth->format('d');
188
- $head .= '<div class="cal_body"></div>';
189
- $head .= '</div>';
190
-
191
- $firstDayOfNextMonth->add(new DateInterval('P1D'));
192
- $nextMonth = $firstDayOfNextMonth->format('Y-m');
193
- }
194
-
195
- echo $tr . $tail . $body . $head;
196
-
197
- ?>
198
-
199
- ```
200
106
  ```php
201
107
  data.php
202
108
  <?php

1

内容の追加編集を行いました。

2019/10/24 03:25

投稿

kenichi_myk
kenichi_myk

スコア14

title CHANGED
File without changes
body CHANGED
@@ -227,4 +227,8 @@
227
227
 
228
228
  ?>
229
229
  ```
230
- ##試したこと
230
+ ##試したこと
231
+ index.phpをロードしたらAjaxでcalendar.phpを読みに行く仕組みになっています。
232
+ foreachの入れ子の仕方、if文の分岐の仕方等トライしてみましたがうまくいきません。
233
+
234
+ プログラミングを始めてまだ初心者で、まだまだ理解できていない点も多々あるかと思いますがよろしくお願いします。