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

質問編集履歴

4

追記

2021/03/05 13:14

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -26,13 +26,188 @@
26
26
  ##完成予想図
27
27
  ![イメージ説明](7cc99624c8ce75a610104000d2893fe5.png)
28
28
  ここに選手の得点履歴として、「点数(何点目か)」「試合日時」「対戦相手」「ゴールタイム」を追加したい。
29
+
30
+ このsql文で上記画像が実装できている
29
- すでに実装ずみのsql文
31
+ Player.php
30
32
  ```
33
+ public function findById($id = 0):Array {
31
- $sql = 'SELECT c.name AS c_name, p.id, p.uniform_num, p.position, p.name, p.club, p.birth, p.height, p.weight
34
+ $sql = 'SELECT c.name AS c_name, p.id, p.uniform_num, p.position, p.name, p.club, p.birth, p.height, p.weight
32
- FROM players p
35
+ FROM players p
33
- INNER JOIN countries c
36
+ INNER JOIN countries c
34
- ON c.id = p.country_id
37
+ ON c.id = p.country_id
35
- WHERE p.id = :id';
38
+ WHERE p.id = :id';
39
+
40
+ $sql_score = 'SELECT
41
+ (
42
+ SELECT
43
+ COUNT(1) + 1
44
+ FROM
45
+ goals g
46
+ INNER JOIN pairings p
47
+ ON g.pairing_id = p.id
48
+ WHERE
49
+ goals.player_id = g.player_id
50
+ AND (
51
+ (
52
+ goals.goal_time > g.goal_time
53
+ AND pairings.kickoff = p.kickoff
54
+ ) OR (
55
+ pairings.kickoff > p.kickoff
56
+ )
57
+ )
58
+ ) AS 点数
59
+ , pairings.kickoff AS 試合日時
60
+ , countries.name AS 対戦相手
61
+ , goals.goal_time AS ゴールタイム
62
+ FROM
63
+ players
64
+ INNER JOIN goals
65
+ ON players.id = goals.player_id
66
+ INNER JOIN pairings
67
+ ON goals.pairing_id = pairings.id
68
+ INNER JOIN countries
69
+ ON pairings.enemy_country_id = countries.id
70
+ WHERE
71
+ players.id = :id
72
+ ORDER BY
73
+ pairings.kickoff
74
+ , goals.goal_time';
75
+
76
+ $sth = $this->dbh->prepare($sql);
77
+ $sth_score = $this->dbh->prepare($sql_score);
78
+ $sth->bindParam(':id', $id, PDO::PARAM_INT);
79
+ $sth_score->bindParam(':id', $id, PDO::PARAM_INT);
80
+ $sth->execute();
81
+ $sth_score->execute();
82
+ $result = $sth->fetch(PDO::FETCH_ASSOC);
83
+ $result_score = $sth_score->fetch(PDO::FETCH_ASSOC);
84
+ return array($result,$result_score);
85
+ }
36
86
  ```
87
+ PlayerControler.php
88
+ ```
89
+ <?php
90
+ require_once(ROOT_PATH .'/Models/Player.php');
91
+ class PlayerController {
92
+ private $request;
93
+ private $player;
94
+ public function __construct() {
95
+ $this->request['get'] = $_GET;
96
+ $this->request['post'] = $_POST;
97
+ $this->Player = new Player();
98
+ }
37
99
 
100
+ public function index() {
101
+ $page = 0;
102
+ if(isset($this->request['get']['page'])) {
103
+ $page = $this->request['get']['page'];
104
+ }
105
+
106
+ $players = $this->Player->findAll($page);
107
+ $players_count = $this->Player->countAll();
108
+ $params = [
109
+ 'players' => $players,
110
+ 'pages' => $players_count / 20
111
+ ];
112
+ return $params;
113
+ }
114
+
115
+ public function view() {
116
+ if(empty($this->request['get']['id'])) {
117
+ echo '指定のパラメーターが不正です。このページを表示できません。';
118
+ exit;
119
+ }
120
+
121
+ $player = $this->Player->findById($this->request['get']['id']);
122
+ $params = [
123
+ 'player' => $player
124
+ ];
125
+ return $params;
126
+ }
127
+ }
128
+ ```
129
+ show.php
130
+ ```
131
+ <?php
132
+ ini_set('display_errors', "On");
133
+ require_once(ROOT_PATH .'Controllers/PlayerController.php');
134
+ require_once(ROOT_PATH .'/Models/Player.php');
135
+ $player = new PlayerController();
136
+ $params = $player->view();
137
+ var_dump($params);
138
+ ?>
139
+
140
+ <!DOCTYPE html>
141
+ <html lang="en">
142
+ <head>
143
+ <meta charset="UTF-8">
144
+ <meta http-equiv="X-UA-Compatible" content="IE=edge">
145
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
146
+ <link rel="stylesheet" href="/css/base.css">
147
+ <title>worldcup</title>
148
+ </head>
149
+ <body>
150
+ <h2>選手詳細</h2>
151
+ <table class="show-table">
152
+ <?php foreach($params['player'] as $player): ?>
153
+ <tr>
154
+ <th>No</th>
155
+ <td><?=$player['id'] ?></td>
156
+ </tr>
157
+ <tr>
158
+ <th>背番号</th>
159
+ <td><?=$player['uniform_num'] ?></td>
160
+ </tr>
161
+ <tr>
162
+ <th>ポジション</th>
163
+ <td><?=$player['position'] ?></td>
164
+ </tr>
165
+ <tr>
166
+ <th>名前</th>
167
+ <td><?=$player['name'] ?></td>
168
+ </tr>
169
+ <tr>
170
+ <th>所属</th>
171
+ <td><?=$player['club'] ?></td>
172
+ </tr>
173
+ <tr>
174
+ <th>誕生日</th>
175
+ <td><?=$player['birth'] ?></td>
176
+ </tr>
177
+ <tr>
178
+ <th>身長</th>
179
+ <td><?=$player['height'] ?>cm</td>
180
+ </tr>
181
+ <tr>
182
+ <th>体重</th>
183
+ <td><?=$player['weight'] ?>kg</td>
184
+ </tr>
185
+ <tr>
186
+ <th>所属国</th>
187
+ <td><?=$player['c_name'] ?></td>
188
+ </tr>
189
+ <tr>
190
+ <th>得点</th>
191
+ <td><?=$player['点数'] ?></td>
192
+ </tr>
193
+ <?php endforeach; ?>
38
- このsql文で上記画像が実装できている
194
+ </table>
195
+ <div class="ed-btn">
196
+ <div class="edit"><a href="show.php?id=<?php echo $player['id'] ?>">編集</a></div>
197
+ <div class="delete"><a href="show.php?id=<?php echo $player['id'] ?>">削除</a></div>
198
+ </div>
199
+ <br>
200
+ <div class="top">
201
+ <a href="index.php">トップへ戻る</a>
202
+ </div>
203
+ </body>
204
+ </html>
205
+
206
+ ```
207
+
208
+ 得点表示
209
+ ![イメージ説明](45eccc0bca4a1e5ceafeddef3a1d7f44.png)
210
+ ![イメージ説明](8327a116d6fab401c7844e01ce7ea924.png)
211
+
212
+ 選手詳細はうまく表示できるのですが、得点が表示できずに困っています。
213
+ var_dumpでも得点部分がbool(false)返ってきます。

3

追記

2021/03/05 13:14

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -25,4 +25,14 @@
25
25
 
26
26
  ##完成予想図
27
27
  ![イメージ説明](7cc99624c8ce75a610104000d2893fe5.png)
28
- ここに選手の得点履歴として、「点数(何点目か)」「試合日時」「対戦相手」「ゴールタイム」を追加したい。
28
+ ここに選手の得点履歴として、「点数(何点目か)」「試合日時」「対戦相手」「ゴールタイム」を追加したい。
29
+ すでに実装ずみのsql文
30
+ ```
31
+ $sql = 'SELECT c.name AS c_name, p.id, p.uniform_num, p.position, p.name, p.club, p.birth, p.height, p.weight
32
+ FROM players p
33
+ INNER JOIN countries c
34
+ ON c.id = p.country_id
35
+ WHERE p.id = :id';
36
+ ```
37
+
38
+ このsql文で上記画像が実装できている

2

完成予想図の追記

2021/03/04 14:22

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -21,4 +21,8 @@
21
21
  pairings_tmpテーブル
22
22
  ![イメージ説明](fe864b57f90d4d0a63a1552158b82965.png)
23
23
  playersテーブル
24
- ![イメージ説明](fbc3233a26a394d6b1e45aae5abd7785.png)
24
+ ![イメージ説明](fbc3233a26a394d6b1e45aae5abd7785.png)
25
+
26
+ ##完成予想図
27
+ ![イメージ説明](7cc99624c8ce75a610104000d2893fe5.png)
28
+ ここに選手の得点履歴として、「点数(何点目か)」「試合日時」「対戦相手」「ゴールタイム」を追加したい。

1

追記

2021/03/04 13:08

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -11,19 +11,14 @@
11
11
  データベース
12
12
 
13
13
  countriesテーブル
14
- ![イメージ説明](180f2f91d66cd8807b5a34c313f0e8cb.png)
14
+ ![イメージ説明](0ced57bebb7211f227a0289c0846adaa.png)
15
-
16
15
  goalsテーブル
17
- ![イメージ説明](c5dd1b2cb035296790aa6283845bbcde.png)
16
+ ![イメージ説明](100b4fefc3381aca763c9bf2526b59ce.png)
18
-
19
17
  goals_tmpテーブル
20
- ![イメージ説明](42c8b3a795b623b7326878843c858601.png)
18
+ ![イメージ説明](c9d8404f4d9e66a32bac10f87ea4cb7c.png)
21
-
22
19
  pairingsテーブル
23
- ![![イメージ説明](68f7f5d7bc77c3c7d728561196606a1f.png)]
20
+ ![イメージ説明](27be86268f71fe7c700b4b080d84c615.png)
24
-
25
21
  pairings_tmpテーブル
26
- ![イメージ説明](d80a31ae942a71f9b24643e0d0effc45.png)
22
+ ![イメージ説明](fe864b57f90d4d0a63a1552158b82965.png)
27
-
28
23
  playersテーブル
29
- ![イメージ説明](c02154543b611c813fe2632fc3a066e6.png)
24
+ ![イメージ説明](fbc3233a26a394d6b1e45aae5abd7785.png)