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

質問編集履歴

3

修正

2018/03/21 13:53

投稿

vowd1
vowd1

スコア53

title CHANGED
File without changes
body CHANGED
@@ -2,63 +2,63 @@
2
2
 
3
3
  下記jsonです。
4
4
  ```json
5
- 1
5
+
6
- 2 {"res":
6
+ {"res":
7
- 3 {"ScheduleData":[
7
+ {"ScheduleData":[
8
- 4 {
8
+ {
9
- 5 "id":"0001",
9
+ "id":"0001",
10
- 6 "title":"サンプル01",
10
+ "title":"サンプル01",
11
- 7 "day":[
11
+ "day":[
12
- 8 {
12
+ {
13
- 9 "year":"2018",
13
+ "year":"2018",
14
- 10 "month":"03",
14
+ "month":"03",
15
- 11 "_day":"31"
15
+ "_day":"31"
16
- 12 }
16
+ }
17
- 13 ],
17
+ ],
18
- 14 "appoint_1":"単体テスト",
18
+ "appoint_1":"単体テスト",
19
- 15 "appoint_2":"javascript勉強会",
19
+ "appoint_2":"javascript勉強会",
20
- 16 "appoint_3":"新規プロジェクトキックオフ",
20
+ "appoint_3":"新規プロジェクトキックオフ",
21
- 17 },
21
+ },
22
- 18 {
22
+ {
23
- 19 "id":"0002",
23
+ "id":"0002",
24
- 20 "title":"サンプル02",
24
+ "title":"サンプル02",
25
- 21 "day":[
25
+ "day":[
26
- 22 {
26
+ {
27
- 23 "year":"2018",
27
+ "year":"2018",
28
- 24 "month":"04",
28
+ "month":"04",
29
- 25 "_day":"01"
29
+ "_day":"01"
30
- 26 }
30
+ }
31
- 27 ],
31
+ ],
32
- 28 "appoint_1":"会議",
32
+ "appoint_1":"会議",
33
- 29 "appoint_2":"要件定義",
33
+ "appoint_2":"要件定義",
34
- 30 "appoint_3":"ログ収集機能改修",
34
+ "appoint_3":"ログ収集機能改修",
35
- 31 }
36
- 32 ]}
35
+ }
37
- 33 }
36
+ ]}
37
+ }
38
38
 
39
39
  ```
40
40
 
41
41
  ```php
42
- 42 private function _getTail() {
42
+ private function _getTail() {
43
- 43
43
+
44
- 44 $url = "jsondata.json";
44
+ $url = "jsondata.json";
45
- 45 $json = file_get_contents($url);
45
+ $json = file_get_contents($url);
46
- 46 $arr = json_decode($json, true);
46
+ $arr = json_decode($json, true);
47
- 47
47
+
48
- 48
48
+
49
- 49 $tail = '';
49
+ $tail = '';
50
- 50 $lastDayOfPrevMonth = new \DateTime('last day of ' . $this->yearMonth . ' -1 month');
50
+ $lastDayOfPrevMonth = new \DateTime('last day of ' . $this->yearMonth . ' -1 month');
51
- 51 while ($lastDayOfPrevMonth->format('w') < 6) {
51
+ while ($lastDayOfPrevMonth->format('w') < 6) {
52
- 52 $tail_pre = sprintf('<td class="gray">%d', $lastDayOfPrevMonth->format('d'));
52
+ $tail_pre = sprintf('<td class="gray">%d', $lastDayOfPrevMonth->format('d'));
53
- 53
53
+
54
- 54 $tail_appoint_1 = sprintf('<ul><li>%s</li>', $arr["res"]["ScheduleData"][0]["appoint_1"]);
54
+ $tail_appoint_1 = sprintf('<ul><li>%s</li>', $arr["res"]["ScheduleData"][0]["appoint_1"]); ←※1
55
- 55 $tail_appoint_2 = sprintf('<li>%s</li></td>', $arr["res"]["ScheduleData"][0]["appoint_2"]);
55
+ $tail_appoint_2 = sprintf('<li>%s</li></td>', $arr["res"]["ScheduleData"][0]["appoint_2"]);
56
- 56 $tail = $tail_pre . $tail_appoint_1 . $tail_appoint_2 . $tail;
56
+ $tail = $tail_pre . $tail_appoint_1 . $tail_appoint_2 . $tail;
57
- 57
57
+
58
- 58 $lastDayOfPrevMonth->sub(new \DateInterval('P1D'));
58
+ $lastDayOfPrevMonth->sub(new \DateInterval('P1D'));
59
- 59 }
59
+ }
60
- 60 return $tail;
60
+ return $tail;
61
- 61 }
61
+ }
62
62
 
63
63
  ```
64
- 上記のphpの54行目のところをforeachで回してid:0001とid:0002もそしてさらに増えても取得してカレンダーに表示できるようにしたいのですが、どのように書き換えるべきでしょうか。
64
+ 上記のphpの※1のところをforeachで回してid:0001とid:0002もそしてさらに増えても取得してカレンダーに表示できるようにしたいのですが、どのように書き換えるべきでしょうか。

2

改修

2018/03/21 13:53

投稿

vowd1
vowd1

スコア53

title CHANGED
File without changes
body CHANGED
@@ -15,9 +15,9 @@
15
15
  11 "_day":"31"
16
16
  12 }
17
17
  13 ],
18
- 14 "appoint_1":"エコ配取材",
18
+ 14 "appoint_1":"単体テスト",
19
- 15 "appoint_2":"scala勉強会",
19
+ 15 "appoint_2":"javascript勉強会",
20
- 16 "appoint_3":"talknoteキックオフ",
20
+ 16 "appoint_3":"新規プロジェクトキックオフ",
21
21
  17 },
22
22
  18 {
23
23
  19 "id":"0002",

1

改修

2018/03/21 13:49

投稿

vowd1
vowd1

スコア53

title CHANGED
File without changes
body CHANGED
@@ -51,8 +51,8 @@
51
51
  51 while ($lastDayOfPrevMonth->format('w') < 6) {
52
52
  52 $tail_pre = sprintf('<td class="gray">%d', $lastDayOfPrevMonth->format('d'));
53
53
  53
54
- 54 $tail_appoint_1 = sprintf('<ul><li>%s</li>', $arr["res"]["blogData"][0]["appoint_1"]);
54
+ 54 $tail_appoint_1 = sprintf('<ul><li>%s</li>', $arr["res"]["ScheduleData"][0]["appoint_1"]);
55
- 55 $tail_appoint_2 = sprintf('<li>%s</li></td>', $arr["res"]["blogData"][0]["appoint_2"]);
55
+ 55 $tail_appoint_2 = sprintf('<li>%s</li></td>', $arr["res"]["ScheduleData"][0]["appoint_2"]);
56
56
  56 $tail = $tail_pre . $tail_appoint_1 . $tail_appoint_2 . $tail;
57
57
  57
58
58
  58 $lastDayOfPrevMonth->sub(new \DateInterval('P1D'));