質問編集履歴

1

コードから商品の個数と金額に関する部分を消去しました。

2021/05/28 08:45

投稿

Keichi_Negishi
Keichi_Negishi

スコア25

test CHANGED
File without changes
test CHANGED
@@ -58,91 +58,243 @@
58
58
 
59
59
  <!--オーダー画面-->
60
60
 
61
+ <form method="post" action="order_confirmation.php">
62
+
63
+ <input type="submit" value="オーダー内容を確認する">
64
+
65
+ <table border="1">
66
+
67
+ <tr><th></th><th>購入者</th><th>商品</th><th>個数</th></tr>
68
+
69
+ <?php
70
+
71
+ //データを全て配列で取得
72
+
73
+ $array_number = 0;
74
+
75
+ $number = 1;
76
+
77
+ while($number<=15) :
78
+
79
+ ?>
80
+
81
+ <tr>
82
+
83
+ <td><?php echo $number ?></td>
84
+
85
+ <td>
86
+
87
+ <select name="person_code[<?php echo $array_number ?>]">
88
+
89
+ <option value="">選択してください</option>
90
+
91
+ <option value="1">購入者1</option>
92
+
93
+ <option value="2">購入者2</option>
94
+
95
+ </select>
96
+
97
+ </td>
98
+
99
+ <td>
100
+
101
+ <select name="item_code[<?php echo $array_number ?>]">
102
+
103
+ <option value="">選択してください</option>
104
+
105
+ <option value="1">商品名1</option>
106
+
107
+ <option value="2">商品名2</option>
108
+
109
+ </select>
110
+
111
+ </td>
112
+
113
+ </tr>
114
+
115
+ <?php
116
+
117
+ $number++;
118
+
119
+ $array_number++;
120
+
121
+ ?>
122
+
123
+ <?php endwhile; ?>
124
+
125
+ </table>
126
+
127
+ </form>
128
+
129
+
130
+
131
+ ```
132
+
133
+
134
+
135
+ **確認画面**
136
+
137
+
138
+
139
+ ```PHP
140
+
61
141
  <?php
62
142
 
143
+
144
+
145
+ $person_code = $_POST['person_code'];
146
+
147
+ $filter_person_code = count(array_filter($person_code));
148
+
63
- date_default_timezone_set('Asia/Tokyo');
149
+ $item_code = $_POST['item_code'];
150
+
151
+
152
+
64
-
153
+ $count_number = 0;
154
+
155
+
156
+
157
+ $p_sql = "SELECT person_name,person_code FROM person_data WHERE person_code = :person_code";
158
+
159
+ $i_sql = "SELECT item_name,item_code FROM item_data WHERE item_code = :item_code";
160
+
161
+
162
+
163
+ //こちらはソートのテスト
164
+
165
+ $sort = null;
166
+
167
+ if(isset($_POST['sort'])){
168
+
65
- $today = date('Y年m月d日');
169
+ $sort = $_POST['sort'];
170
+
171
+ }
172
+
173
+ if($sort == 'n'){
174
+
175
+ echo '名前順にソート';
176
+
177
+ }elseif($sort == 'i'){
178
+
179
+ echo '商品名順にソート';
180
+
181
+ $i_sql = "SELECT item_name,item_code,price FROM item_data WHERE item_code = :item_code ORDER BY item_name DESC";
182
+
183
+ }
184
+
185
+
66
186
 
67
187
  ?>
68
188
 
189
+
190
+
191
+ <section class="common_wrapper">
192
+
193
+ <h1>オーダー確認ページ</h1>
194
+
195
+ <div class="data_list_wrapper">
196
+
69
- <form method="post" action="order_confirmation.php">
197
+ <form method="post" action="order_confirmation.php" onchange="submit(this.form)">
70
-
71
- <p style="padding-bottom: 30px;"><input type="submit" value="オーダー内容を確認する"></p>
198
+
72
-
73
- <table border="1">
74
-
75
- <tr><th></th><th>購入者</th><th>商品</th><th>個数</th></tr>
76
-
77
- <?php
78
-
79
- //データを全て配列で取得
80
-
81
- $array_number = 0;
82
-
83
- $number = 1;
84
-
85
- while($number<=15) :
86
-
87
- ?>
88
-
89
- <tr>
90
-
91
- <td><?php echo $number ?></td>
92
-
93
- <td>
94
-
95
- <select name="person_code[<?php echo $array_number ?>]">
199
+ <select class="select_box" name="sort">
200
+
96
-
201
+ <option value="n">名前順にソート</option>
202
+
97
- <option value="">選択してください</option>
203
+ <option value="i">商品名順にソート</option>
98
-
99
- <option value="0"><?php echo sprintf("%04d", 0) . ':施設' ?></option>
100
-
101
- <?php foreach($p_rows as $p) : ?>
102
-
103
- <option value="<?php echo $p['person_code'] ?>"><?php echo h(sprintf("%04d", $p['person_code'])) . ':' . h($p['person_name']) ?></option>
104
-
105
- <?php endforeach; ?>
106
204
 
107
205
  </select>
108
206
 
109
- </td>
110
-
111
- <td>
112
-
113
- <select name="item_code[<?php echo $array_number ?>]">
114
-
115
- <option value="">選択してください</option>
116
-
117
- <?php foreach($i_rows as $i) : ?>
118
-
119
- <option value="<?php echo $i['item_code'] ?>"><?php echo h($i['item_name']) . ':' . h($i['price']) . '円' ?></option>
120
-
121
- <?php endforeach; ?>
122
-
123
- </select>
124
-
125
- </td>
126
-
127
- <td><input type="number" name="quantity[<?php echo $array_number ?>]" min="0">個</td>
128
-
129
- </tr>
130
-
131
- <?php
132
-
133
- $number++;
134
-
135
- $array_number++;
136
-
137
- ?>
138
-
139
- <?php endwhile; ?>
140
-
141
- </table>
142
-
143
- <input type="hidden" name="created_at">
144
-
145
- </form>
207
+ <?php while($count_number <= $filter_person_code) : ?>
208
+
209
+ <input type="hidden" name="person_code[]" value="<?php echo $person_code[$count_number] ?>">
210
+
211
+ <input type="hidden" name="item_code[]" value="<?php echo $item_code[$count_number] ?>">
212
+
213
+ <?php $count_number++; ?>
214
+
215
+ <?php endwhile; ?>
216
+
217
+ </form>
218
+
219
+ //$count_numberを初期化
220
+
221
+ <?php $count_number = 0; ?>
222
+
223
+
224
+
225
+ <table border="1" class="order_confirmation">
226
+
227
+ <tr><th>購入者</th><th>商品</th><th>個数</th><th>金額</th></tr>
228
+
229
+ <?php while($count_number <= $filter_person_code) : ?>
230
+
231
+ <?php
232
+
233
+ $pdo = new pdo(DSN,DB_USER,DB_PASS);
234
+
235
+ //入居者データ
236
+
237
+ $p_data = $pdo->prepare($p_sql);
238
+
239
+ $p_data->bindParam(":person_code", $person_code[$count_number]);
240
+
241
+ $p_data->execute();
242
+
243
+ $p_rows = $p_data->fetchAll(PDO::FETCH_ASSOC);
244
+
245
+
246
+
247
+ $i_data = $pdo->prepare($i_sql);
248
+
249
+ $i_data->bindParam(":item_code", $item_code[$count_number]);
250
+
251
+ $i_data->execute();
252
+
253
+ $i_rows = $i_data->fetchAll(PDO::FETCH_ASSOC);
254
+
255
+ $pdo = '';
256
+
257
+ ?>
258
+
259
+ <tr>
260
+
261
+ <td>
262
+
263
+ <?php
264
+
265
+ foreach($p_rows as $p) :
266
+
267
+ echo h(sprintf("%03d", $p['person_code'])) . ':' . h($p['person_name']);
268
+
269
+ endforeach;
270
+
271
+ ?>
272
+
273
+ </td>
274
+
275
+ <td>
276
+
277
+ <?php foreach($i_rows as $i) :
278
+
279
+ $item_name = $i['item_name'];
280
+
281
+ echo h($item_name);
282
+
283
+ endforeach; ?>
284
+
285
+ </td>
286
+
287
+ </tr>
288
+
289
+ <?php $count_number++; ?>
290
+
291
+ <?php endwhile; ?>
292
+
293
+ </table>
294
+
295
+ </div><!--/.data_list_wrapper -->
296
+
297
+ </section><!--/.common_wrapper -->
146
298
 
147
299
 
148
300
 
@@ -150,234 +302,6 @@
150
302
 
151
303
 
152
304
 
153
- **確認画面**
154
-
155
-
156
-
157
- ```PHP
158
-
159
- <?php
160
-
161
-
162
-
163
- $person_code = $_POST['person_code'];
164
-
165
- $filter_person_code = count(array_filter($person_code));
166
-
167
- $item_code = $_POST['item_code'];
168
-
169
- $quantity = $_POST['quantity'];
170
-
171
- $created_at = $_POST['created_at'];
172
-
173
-
174
-
175
- $count_number = 0;
176
-
177
-
178
-
179
- $p_sql = "SELECT person_name,person_code FROM person_data WHERE person_code = :person_code";
180
-
181
- $i_sql = "SELECT item_name,item_code,price FROM item_data WHERE item_code = :item_code";
182
-
183
-
184
-
185
- //こちらはソートのテスト
186
-
187
- $sort = null;
188
-
189
- if(isset($_POST['sort'])){
190
-
191
- $sort = $_POST['sort'];
192
-
193
- }
194
-
195
- if($sort == 'n'){
196
-
197
- echo '名前順にソート';
198
-
199
- }elseif($sort == 'i'){
200
-
201
- echo '商品名順にソート';
202
-
203
- $i_sql = "SELECT item_name,item_code,price FROM item_data WHERE item_code = :item_code ORDER BY item_name DESC";
204
-
205
- }
206
-
207
-
208
-
209
- ?>
210
-
211
-
212
-
213
- <section class="common_wrapper">
214
-
215
- <h1>オーダー確認ページ</h1>
216
-
217
- <div class="data_list_wrapper">
218
-
219
- <div class="sort_block">
220
-
221
- <form method="post" action="order_confirmation.php" onchange="submit(this.form)">
222
-
223
- <select class="select_box" name="sort">
224
-
225
- <option value="n">名前順にソート</option>
226
-
227
- <option value="i">商品名順にソート</option>
228
-
229
- </select>
230
-
231
- <?php while($count_number <= $filter_person_code) : ?>
232
-
233
- <input type="hidden" name="person_code[]" value="<?php echo $person_code[$count_number] ?>">
234
-
235
- <input type="hidden" name="item_code[]" value="<?php echo $item_code[$count_number] ?>">
236
-
237
- <input type="hidden" name="quantity[]" value="<?php echo $quantity[$count_number] ?>">
238
-
239
- <input type="hidden" name="created_at[]" value="<?php echo $created_at[$count_number] ?>">
240
-
241
- <?php $count_number++; ?>
242
-
243
- <?php endwhile; ?>
244
-
245
- </form>
246
-
247
- </div><!--/.sort_block -->
248
-
249
-
250
-
251
- <?php $count_number = 0; ?>
252
-
253
-
254
-
255
- <table border="1" class="order_confirmation">
256
-
257
- <tr><th>購入者</th><th>商品</th><th>個数</th><th>金額</th></tr>
258
-
259
- <?php while($count_number <= $filter_person_code) : ?>
260
-
261
- <?php
262
-
263
- $pdo = new pdo(DSN,DB_USER,DB_PASS);
264
-
265
- //入居者データ
266
-
267
- $p_data = $pdo->prepare($p_sql);
268
-
269
- $p_data->bindParam(":person_code", $person_code[$count_number]);
270
-
271
- $p_data->execute();
272
-
273
- $p_rows = $p_data->fetchAll(PDO::FETCH_ASSOC);
274
-
275
-
276
-
277
- $i_data = $pdo->prepare($i_sql);
278
-
279
- $i_data->bindParam(":item_code", $item_code[$count_number]);
280
-
281
- $i_data->execute();
282
-
283
- $i_rows = $i_data->fetchAll(PDO::FETCH_ASSOC);
284
-
285
- $pdo = '';
286
-
287
- ?>
288
-
289
- <tr>
290
-
291
- <td>
292
-
293
- <?php
294
-
295
- if($person_code[$count_number] == 0) :
296
-
297
- echo sprintf("%04d", 0) . ':' . '施設';
298
-
299
- else :
300
-
301
- foreach($p_rows as $p) :
302
-
303
- echo h(sprintf("%03d", $p['person_code'])) . ':' . h($p['person_name']);
304
-
305
- endforeach;
306
-
307
- endif;
308
-
309
- ?>
310
-
311
- </td>
312
-
313
- <td>
314
-
315
- <?php foreach($i_rows as $i) :
316
-
317
- $item_name = $i['item_name'];
318
-
319
- //echo h($i['item_name']);
320
-
321
- echo h($item_name);
322
-
323
- endforeach; ?>
324
-
325
- </td>
326
-
327
- <td>
328
-
329
- <?php echo h($quantity[$count_number]); ?>
330
-
331
- </td>
332
-
333
- <td>
334
-
335
- <?php
336
-
337
- $subtotal = null;
338
-
339
- $price = null;
340
-
341
- //$quantity変数を繰り返し使用できるように変数名を変更する
342
-
343
- $q_individual = $quantity[$count_number];
344
-
345
- foreach($i_rows as $i) :
346
-
347
- $price = $i['price'];
348
-
349
- //echo h($i['price']);
350
-
351
- //echo $subtotal;
352
-
353
- endforeach;
354
-
355
- $subtotal = $price * $q_individual;
356
-
357
- echo h($subtotal) . '円';
358
-
359
- ?>
360
-
361
- </td>
362
-
363
- </tr>
364
-
365
- <?php $count_number++; ?>
366
-
367
- <?php endwhile; ?>
368
-
369
- </table>
370
-
371
- </div><!--/.data_list_wrapper -->
372
-
373
- </section><!--/.common_wrapper -->
374
-
375
-
376
-
377
- ```
378
-
379
-
380
-
381
305
  ご回答頂けると嬉しいです。
382
306
 
383
307
  よろしくお願いします。