質問編集履歴
1
検索ページのformと、検索処理、データベースへの接続のコードを追記しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -55,3 +55,379 @@
|
|
55
55
|
PHP 7.1.23
|
56
56
|
|
57
57
|
mysql 5.6.43
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
```php
|
62
|
+
|
63
|
+
//検索ページのform
|
64
|
+
|
65
|
+
<form method="post" action="sales_report_choiceCheck.php" class="" name="sales_report_check_form" onSubmit="return formCheck()">
|
66
|
+
|
67
|
+
<table id="table" class="search">
|
68
|
+
|
69
|
+
<tr>
|
70
|
+
|
71
|
+
<th style="width:110px;">営業担当者<br>で絞る</th>
|
72
|
+
|
73
|
+
<!-- ①選択条件でドライバーを選択するためにドライバー一覧を取得 -->
|
74
|
+
|
75
|
+
<td>
|
76
|
+
|
77
|
+
<select name="driver_id" id="driver_id">
|
78
|
+
|
79
|
+
<option value="<?php echo $rec['driver_id'] . '-' . $rec['first_name'] . $rec['last_name']; ?>">
|
80
|
+
|
81
|
+
<?php echo $rec['first_name'] . $rec['last_name']; ?>
|
82
|
+
|
83
|
+
</option>
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
<?php
|
88
|
+
|
89
|
+
try {
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
$dbh = new PDO('mysql:host='.DB_HOST.';dbname='.DB_NAME, DB_USER, DB_PASSWORD, $options);
|
94
|
+
|
95
|
+
$dbh->query('SET NAMES utf8');
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
$sql = "SELECT * FROM m_driver_master WHERE retirement=0";
|
100
|
+
|
101
|
+
$stmt = $dbh->prepare($sql);
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
$stmt->execute();
|
106
|
+
|
107
|
+
$dbh = null;
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
while(true) {
|
112
|
+
|
113
|
+
$rec = $stmt->fetch(PDO::FETCH_ASSOC);
|
114
|
+
|
115
|
+
if($rec === false) {
|
116
|
+
|
117
|
+
break;
|
118
|
+
|
119
|
+
}
|
120
|
+
|
121
|
+
echo '<option name="driver_id" value="' . $rec['driver_id'] . '-' . $rec['first_name'] . $rec['last_name'] . '">' . $rec['first_name'] . $rec['last_name'] . '</option>';
|
122
|
+
|
123
|
+
}
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
} catch (PDOException $e) {
|
128
|
+
|
129
|
+
exit('顧客データベース接続失敗。'.$e->getMessage());
|
130
|
+
|
131
|
+
}
|
132
|
+
|
133
|
+
?>
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
</select>
|
138
|
+
|
139
|
+
</td>
|
140
|
+
|
141
|
+
</tr>
|
142
|
+
|
143
|
+
|
144
|
+
|
145
|
+
<tr>
|
146
|
+
|
147
|
+
<th style="width:110px;">顧客名で<br>絞る</th>
|
148
|
+
|
149
|
+
<!-- ②選択条件で顧客名を選択するために顧客一覧を取得 -->
|
150
|
+
|
151
|
+
<td>
|
152
|
+
|
153
|
+
<select name="salesClient_id" id="salesClient_id">
|
154
|
+
|
155
|
+
<option value="<?php echo $rec2['salesClient_id'] . '-' . $rec2['shop_name']; ?>">
|
156
|
+
|
157
|
+
<?php echo $rec2['shop_name']; ?>
|
158
|
+
|
159
|
+
</option>
|
160
|
+
|
161
|
+
|
162
|
+
|
163
|
+
<?php
|
164
|
+
|
165
|
+
try {
|
166
|
+
|
167
|
+
|
168
|
+
|
169
|
+
$dbh = new PDO('mysql:host='.DB_HOST.';dbname='.DB_NAME, DB_USER, DB_PASSWORD, $options);
|
170
|
+
|
171
|
+
$dbh->query('SET NAMES utf8');
|
172
|
+
|
173
|
+
|
174
|
+
|
175
|
+
$sql = "SELECT * FROM m_salesClient_master WHERE 1";
|
176
|
+
|
177
|
+
$stmt = $dbh->prepare($sql);
|
178
|
+
|
179
|
+
|
180
|
+
|
181
|
+
$stmt->execute();
|
182
|
+
|
183
|
+
$dbh = null;
|
184
|
+
|
185
|
+
|
186
|
+
|
187
|
+
while(true) {
|
188
|
+
|
189
|
+
$rec2 = $stmt->fetch(PDO::FETCH_ASSOC);
|
190
|
+
|
191
|
+
if($rec2 === false) {
|
192
|
+
|
193
|
+
break;
|
194
|
+
|
195
|
+
}
|
196
|
+
|
197
|
+
echo '<option name="salesClient_id" value="' . $rec2['salesClient_id'] . '-' . $rec2['shop_name'] . '">' . $rec2['shop_name'] . '</option>';
|
198
|
+
|
199
|
+
}
|
200
|
+
|
201
|
+
|
202
|
+
|
203
|
+
} catch (PDOException $e) {
|
204
|
+
|
205
|
+
exit('顧客データベース接続失敗。'.$e->getMessage());
|
206
|
+
|
207
|
+
}
|
208
|
+
|
209
|
+
?>
|
210
|
+
|
211
|
+
</select>
|
212
|
+
|
213
|
+
</td>
|
214
|
+
|
215
|
+
</tr>
|
216
|
+
|
217
|
+
|
218
|
+
|
219
|
+
<tr>
|
220
|
+
|
221
|
+
<th style="width:110px;">日付で絞る</th>
|
222
|
+
|
223
|
+
<!-- ③日付を選択するためのカレンダー -->
|
224
|
+
|
225
|
+
<td>
|
226
|
+
|
227
|
+
<div class="calendar-inner">
|
228
|
+
|
229
|
+
<input class="calendar" type="date" name="sales_date" value="">
|
230
|
+
|
231
|
+
<img class="calendar-icon" src="../../images/icon_calendar.png">
|
232
|
+
|
233
|
+
</div>
|
234
|
+
|
235
|
+
</td>
|
236
|
+
|
237
|
+
</tr>
|
238
|
+
|
239
|
+
</table>
|
240
|
+
|
241
|
+
|
242
|
+
|
243
|
+
|
244
|
+
|
245
|
+
<!-- 登録ボタン -->
|
246
|
+
|
247
|
+
<div class="button">
|
248
|
+
|
249
|
+
<input type="submit" class="search_button" value="検索">
|
250
|
+
|
251
|
+
<p id="notice_9" class="input">必須項目は全て入力して下さい</p>
|
252
|
+
|
253
|
+
</div>
|
254
|
+
|
255
|
+
</form>
|
256
|
+
|
257
|
+
```
|
258
|
+
|
259
|
+
```php
|
260
|
+
|
261
|
+
//検索処理、データベースへの接続
|
262
|
+
|
263
|
+
|
264
|
+
|
265
|
+
// 条件なし
|
266
|
+
|
267
|
+
if(empty($driver_id) && empty($salesClient_id) && empty($sales_date)) {
|
268
|
+
|
269
|
+
$search_condition = 1;
|
270
|
+
|
271
|
+
|
272
|
+
|
273
|
+
// driver_id軸条件
|
274
|
+
|
275
|
+
} else if(!empty($driver_id) && empty($salesClient_id) && empty($sales_date)) {
|
276
|
+
|
277
|
+
$search_condition = 'a.driver_id=' . $driver_id;
|
278
|
+
|
279
|
+
}
|
280
|
+
|
281
|
+
if(!empty($driver_id) && empty($salesClient_id) && !empty($sales_date)) {
|
282
|
+
|
283
|
+
$search_condition = 'a.driver_id=' . $driver_id . ' AND sales_date=\'' . $sales_date . "'";
|
284
|
+
|
285
|
+
}
|
286
|
+
|
287
|
+
if(!empty($driver_id) && !empty($salesClient_id) && empty($sales_date)) {
|
288
|
+
|
289
|
+
$search_condition = 'a.driver_id=' . $driver_id . ' AND a.salesClient_id=' . $salesClient_id;
|
290
|
+
|
291
|
+
|
292
|
+
|
293
|
+
|
294
|
+
|
295
|
+
// salesClient_id軸条件
|
296
|
+
|
297
|
+
} else if(empty($driver_id) && !empty($salesClient_id) && empty($sales_date)) {
|
298
|
+
|
299
|
+
$search_condition = 'a.salesClient_id=' . $salesClient_id;
|
300
|
+
|
301
|
+
}
|
302
|
+
|
303
|
+
if(empty($driver_id) && !empty($salesClient_id) && !empty($sales_date)) {
|
304
|
+
|
305
|
+
$search_condition = 'a.salesClient_id=' . $salesClient_id . ' AND sales_date=\'' . $sales_date . "'";
|
306
|
+
|
307
|
+
|
308
|
+
|
309
|
+
|
310
|
+
|
311
|
+
// sales_date軸条件
|
312
|
+
|
313
|
+
} else if(empty($driver_id) && empty($salesClient_id) && !empty($sales_date)) {
|
314
|
+
|
315
|
+
$search_condition = 'sales_date=\'' . $sales_date . "'";
|
316
|
+
|
317
|
+
|
318
|
+
|
319
|
+
// すべてに条件設定
|
320
|
+
|
321
|
+
|
322
|
+
|
323
|
+
} else if(!empty($driver_id) && !empty($salesClient_id) && !empty($sales_date)) {
|
324
|
+
|
325
|
+
$search_condition = 'a.driver_id=' . $driver_id . ' AND a.salesClient_id=' . $salesClient_id. ' AND sales_date=\'' . $sales_date . "'";
|
326
|
+
|
327
|
+
}
|
328
|
+
|
329
|
+
|
330
|
+
|
331
|
+
|
332
|
+
|
333
|
+
try {
|
334
|
+
|
335
|
+
$dbh = new PDO('mysql:host='.DB_HOST.';dbname='.DB_NAME, DB_USER, DB_PASSWORD, $options);
|
336
|
+
|
337
|
+
$dbh->query('SET NAMES utf8');
|
338
|
+
|
339
|
+
|
340
|
+
|
341
|
+
$sql = "SELECT * FROM t_sales_db AS a
|
342
|
+
|
343
|
+
JOIN m_salesClient_master AS c ON a.salesClient_id=c.salesClient_id
|
344
|
+
|
345
|
+
JOIN m_sales_progress_master AS d ON a.progress_id=d.progress_id
|
346
|
+
|
347
|
+
JOIN m_sales_progress_purpose_master AS e ON a.progress_purpose_id=e.progress_purpose_id
|
348
|
+
|
349
|
+
JOIN m_driver_master AS b ON a.driver_id=b.driver_id
|
350
|
+
|
351
|
+
WHERE " . $search_condition . " ORDER BY sales_date DESC";
|
352
|
+
|
353
|
+
|
354
|
+
|
355
|
+
|
356
|
+
|
357
|
+
$stmt = $dbh->prepare($sql);
|
358
|
+
|
359
|
+
$stmt->execute();
|
360
|
+
|
361
|
+
|
362
|
+
|
363
|
+
while($result = $stmt->fetch(PDO::FETCH_ASSOC)) {
|
364
|
+
|
365
|
+
$salesdata[] = $result;
|
366
|
+
|
367
|
+
}
|
368
|
+
|
369
|
+
|
370
|
+
|
371
|
+
|
372
|
+
|
373
|
+
$sql = "SELECT * FROM t_competitor_status_db AS a
|
374
|
+
|
375
|
+
JOIN m_shouhinn_master AS b ON a.shouhinn_code = b.shouhinn_code
|
376
|
+
|
377
|
+
JOIN m_driver_master AS c ON a.driver_id=c.driver_id
|
378
|
+
|
379
|
+
JOIN m_salesClient_master AS d ON a.salesClient_id=d.salesClient_id
|
380
|
+
|
381
|
+
ORDER BY reflash_date DESC LIMIT 5";
|
382
|
+
|
383
|
+
|
384
|
+
|
385
|
+
$stmt = $dbh->prepare($sql);
|
386
|
+
|
387
|
+
$stmt->execute();
|
388
|
+
|
389
|
+
|
390
|
+
|
391
|
+
while($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
|
392
|
+
|
393
|
+
$competitorData[] = $row;
|
394
|
+
|
395
|
+
}
|
396
|
+
|
397
|
+
|
398
|
+
|
399
|
+
$sql = "SELECT driver_id FROM m_driver_master
|
400
|
+
|
401
|
+
WHERE " .$_SESSION['login'] = 1;
|
402
|
+
|
403
|
+
|
404
|
+
|
405
|
+
$stmt = $dbh->prepare($sql);
|
406
|
+
|
407
|
+
$stmt->execute();
|
408
|
+
|
409
|
+
|
410
|
+
|
411
|
+
while($thirdResult = $stmt->fetch(PDO::FETCH_ASSOC)) {
|
412
|
+
|
413
|
+
$driversId = $thirdResult;
|
414
|
+
|
415
|
+
}
|
416
|
+
|
417
|
+
|
418
|
+
|
419
|
+
|
420
|
+
|
421
|
+
$dbh = null;
|
422
|
+
|
423
|
+
|
424
|
+
|
425
|
+
|
426
|
+
|
427
|
+
} catch (PDOException $e) {
|
428
|
+
|
429
|
+
exit('顧客データベース接続失敗。'.$e->getMessage());
|
430
|
+
|
431
|
+
}
|
432
|
+
|
433
|
+
```
|