回答編集履歴

3

調整

2017/10/16 14:28

投稿

yambejp
yambejp

スコア114814

test CHANGED
@@ -392,7 +392,7 @@
392
392
 
393
393
  $stmt = $pdo->prepare($sql);
394
394
 
395
- $stmt->execute([]);
395
+ $stmt->execute($data);
396
396
 
397
397
  */
398
398
 

2

調整

2017/10/16 14:28

投稿

yambejp
yambejp

スコア114814

test CHANGED
@@ -260,8 +260,12 @@
260
260
 
261
261
 
262
262
 
263
+ ※テストのため、以下のソースを適当な名前のphpに保存して実行して下さい
264
+
263
265
  ```PHP
264
266
 
267
+ <?PHP
268
+
265
269
  $todofuken1=filter_input(INPUT_POST,"todofuken1");
266
270
 
267
271
  $job_type=filter_input(INPUT_POST,"SHOKUSHU_CD",FILTER_DEFAULT,["options"=>["default"=>[]],"flags"=>FILTER_REQUIRE_ARRAY]);
@@ -392,4 +396,124 @@
392
396
 
393
397
  */
394
398
 
399
+ ?>
400
+
401
+ <form method="POST">
402
+
403
+ <table>
404
+
405
+ <tbody>
406
+
407
+ <tr>
408
+
409
+ <th>勤務地を指定</th>
410
+
411
+ <td>
412
+
413
+ <select name="todofuken1" id="todofuken1">
414
+
415
+ <option value="">都道府県を選択</option>
416
+
417
+ <option value="13">東京都</option>
418
+
419
+ <option value="14">神奈川県</option>
420
+
421
+ <option value="15">埼玉県</option>
422
+
423
+ <option value="16">千葉県</option>
424
+
425
+ </select>
426
+
427
+ </td>
428
+
429
+ </tr>
430
+
431
+ <tr><th>職種を指定</th>
432
+
433
+ <td>
434
+
435
+ <div class="three_line clear">
436
+
437
+ <input type="checkbox" name="SHOKUSHU_CD[]" value="1" id="shokushuLoop1">
438
+
439
+ <label for="shokushuLoop1">オフィスワーク・事務</label>
440
+
441
+ <input type="checkbox" name="SHOKUSHU_CD[]" value="2" id="shokushuLoop2">
442
+
443
+ <label for="shokushuLoop2">営業・販売・サービス</label>
444
+
445
+ <input type="checkbox" name="SHOKUSHU_CD[]" value="3" id="shokushuLoop3">
446
+
447
+ <label for="shokushuLoop3">Web・クリエイティブ</label>
448
+
449
+ </div>
450
+
451
+ </td>
452
+
453
+ </tr>
454
+
455
+ <tr><th>時給を指定</th>
456
+
457
+ <td>
458
+
459
+ <input type="text" class="text_input_s" name="PAY_START" maxlength="8" size="8" value="" style="ime-mode:disabled">&nbsp;円以上?
460
+
461
+ </td>
462
+
463
+ </tr>
464
+
465
+ <tr><th>キーワードを指定</th><td><input type="text" class="text_input_l" name="FREE_KEYWORD" maxlength="30" size="20" value="" style="ime-mode:active" placeholder="キーワードを入力してください。"></td></tr>
466
+
467
+ <tr>
468
+
469
+ <th>こだわり条件を指定</th>
470
+
471
+ <td>
472
+
473
+ <div class="accordion_block">
474
+
475
+ <h2 style="background-image: url(&quot;../../img/common/icon_arrow_up01.png&quot;);">働き方・特徴</h2>
476
+
477
+ <div class="accordion_box three_line clearfix" style="display: block;">
478
+
479
+ <input type="checkbox" name="TOKUCYO[]" value="紹介予定派遣" id="tokucyoLoop1101"><label for="tokucyoLoop1101">紹介予定派遣</label>
480
+
481
+ <input type="checkbox" name="TOKUCYO[]" value="1日7時間未満" id="tokucyoLoop1102"><label for="tokucyoLoop1102">1日7時間未満</label>
482
+
483
+ </div>
484
+
485
+ </div>
486
+
487
+ <div class="accordion_block">
488
+
489
+ <h2 style="background-image: url(&quot;../../img/common/icon_arrow_up01.png&quot;);">業界</h2>
490
+
491
+ <div class="accordion_box three_line clearfix" style="display: block;">
492
+
493
+ <input type="checkbox" name="GYOUKAI[]" value="マスコミ関連" id="tokucyoLoop3301"><label for="tokucyoLoop3301">マスコミ関連</label>
494
+
495
+ <input type="checkbox" name="GYOUKAI[]" value="金融関連" id="tokucyoLoop3302"><label for="tokucyoLoop3302">金融関連</label>
496
+
497
+ <input type="checkbox" name="GYOUKAI[]" value="流通・サービス関連" id="tokucyoLoop3303"><label for="tokucyoLoop3303">流通・サービス関連</label>
498
+
499
+ <input type="checkbox" name="GYOUKAI[]" value="IT・Web関連" id="tokucyoLoop3304"><label for="tokucyoLoop3304">IT・Web関連</label>
500
+
501
+ </div>
502
+
503
+ </div>
504
+
505
+ </td>
506
+
507
+ </tr>
508
+
509
+ </tbody>
510
+
511
+ </table>
512
+
513
+ <p class="center"><input type="submit" value="この条件で検索する"></p>
514
+
515
+ </form>
516
+
517
+
518
+
395
519
  ```

1

修正・追記

2017/10/16 11:49

投稿

yambejp
yambejp

スコア114814

test CHANGED
@@ -84,7 +84,7 @@
84
84
 
85
85
  $sql.="OR work_type IN (".implode(",",array_fill(0,count($work_type),"?")).") ";
86
86
 
87
- $data[]=$work_type;
87
+ $data=array_merge($data,$work_type); /*記載ミス訂正*/
88
88
 
89
89
  }
90
90
 
@@ -92,7 +92,7 @@
92
92
 
93
93
  $sql.="OR gyoukai IN (".implode(",",array_fill(0,count($gyoukai),"?")).") ";
94
94
 
95
- $data[]=$gyoukai;
95
+ $data=array_merge($data,$gyoukai); /*記載ミス訂正*/
96
96
 
97
97
  }
98
98
 
@@ -249,3 +249,147 @@
249
249
 
250
250
 
251
251
  ```
252
+
253
+ ※一部記載ミスを訂正しました
254
+
255
+ # より標準SQLらしく
256
+
257
+ 1や0で処理していたものをvariantに変えました
258
+
259
+ またINをORの羅列に変えました
260
+
261
+
262
+
263
+ ```PHP
264
+
265
+ $todofuken1=filter_input(INPUT_POST,"todofuken1");
266
+
267
+ $job_type=filter_input(INPUT_POST,"SHOKUSHU_CD",FILTER_DEFAULT,["options"=>["default"=>[]],"flags"=>FILTER_REQUIRE_ARRAY]);
268
+
269
+ $jikyu=filter_input(INPUT_POST,"PAY_START",FILTER_VALIDATE_INT);
270
+
271
+ $work_type=filter_input(INPUT_POST,"TOKUCYO",FILTER_DEFAULT,["options"=>["default"=>[]],"flags"=>FILTER_REQUIRE_ARRAY]);
272
+
273
+ $gyoukai=filter_input(INPUT_POST,"GYOUKAI",FILTER_DEFAULT,["options"=>["default"=>[]],"flags"=>FILTER_REQUIRE_ARRAY]);
274
+
275
+
276
+
277
+ $data=[];
278
+
279
+
280
+
281
+
282
+
283
+ $sql ="SELECT * ";
284
+
285
+ $sql.=" FROM kyujin ";
286
+
287
+ $sql.="LEFT JOIN job_type ";
288
+
289
+ $sql.=" ON kyujin.job_type=job_type.id ";
290
+
291
+ $sql.=" LEFT JOIN area ";
292
+
293
+ $sql.=" ON kyujin.area = area.id ";
294
+
295
+ $sql.=" where true ";
296
+
297
+
298
+
299
+ $flg[0]=(!is_null($todofuken1) and $todofuken1!=="");
300
+
301
+ $flg[1]=count($job_type)>0;
302
+
303
+ $flg[2]=$jikyu>0;
304
+
305
+ $flg[3]=count($work_type)>0;
306
+
307
+ $flg[4]=count($gyoukai)>0;
308
+
309
+
310
+
311
+ if($flg[0]){
312
+
313
+ $sql.="AND kyujin.area = ? ";
314
+
315
+ $data[]=$todofuken1;
316
+
317
+ }
318
+
319
+ if($flg[1] or $flg[2] or $flg[3] or $flg[4]){
320
+
321
+ $sql.="AND ( false ";
322
+
323
+ if($flg[1]){
324
+
325
+ foreach($job_type as $val){
326
+
327
+ $sql.="OR kyujin.job_type = ? ";
328
+
329
+ $data[]=$val;
330
+
331
+ }
332
+
333
+ }
334
+
335
+ if($flg[2]){
336
+
337
+ $sql.="OR jikyu>=? ";
338
+
339
+ $data[]=$jikyu;
340
+
341
+ }
342
+
343
+ if($flg[3]){
344
+
345
+ foreach($work_type as $val){
346
+
347
+ $sql.="OR work_type = ? ";
348
+
349
+ $data[]=$val;
350
+
351
+ }
352
+
353
+ }
354
+
355
+ if($flg[4]){
356
+
357
+ foreach($gyoukai as $val){
358
+
359
+ $sql.="OR gyoukai = ? ";
360
+
361
+ $data[]=$val;
362
+
363
+ }
364
+
365
+ }
366
+
367
+ $sql.=") ";
368
+
369
+ }
370
+
371
+
372
+
373
+ if(!in_array(true,$flg)){
374
+
375
+ $sql.="AND false ";
376
+
377
+ }
378
+
379
+
380
+
381
+ print $sql;
382
+
383
+ print "<hr>";
384
+
385
+ print_r($data);
386
+
387
+ /*
388
+
389
+ $stmt = $pdo->prepare($sql);
390
+
391
+ $stmt->execute([]);
392
+
393
+ */
394
+
395
+ ```