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

回答編集履歴

1

ちょうせい

2021/06/03 02:49

投稿

yambejp
yambejp

スコア118102

answer CHANGED
@@ -5,18 +5,17 @@
5
5
  $date =filter_input(INPUT_POST,'date');
6
6
  $data =[];
7
7
  $sql='SELECT * FROM items where 1 ';
8
- if(array_filter([$number,$name,$date],function($x){
8
+ if(count(array_filter([$number,$name,$date],function($x){
9
9
  return !empty($x);
10
- })){
10
+ }))==0){
11
+ $sql.=" and 0";
12
+ }
11
- foreach(["number","name","date"] as $val){
13
+ foreach(["number","name","date"] as $val){
12
- if($$val){
14
+ if($$val){
13
- $sql.=" and {$val}=?";
15
+ $sql.=" and {$val}=?";
14
- $data[]=$$val;
16
+ $data[]=$$val;
15
- }
16
17
  }
17
- }else{
18
- $sql.=" and 0";
19
- };
18
+ }
20
19
  print $sql.";<br>\n";
21
20
  print_r($data);
22
21
  ?>
@@ -27,4 +26,5 @@
27
26
  date:<input name="date" value=""><br>
28
27
  <input type="submit" value="send">
29
28
  </form>
30
- ```
29
+ ```
30
+ ※一部フローを調整