回答編集履歴
2
追記
test
CHANGED
@@ -57,3 +57,49 @@
|
|
57
57
|
?>
|
58
58
|
|
59
59
|
```
|
60
|
+
|
61
|
+
# あいまい検索
|
62
|
+
|
63
|
+
- その1
|
64
|
+
|
65
|
+
```PHP
|
66
|
+
|
67
|
+
if($keyword!=="" and is_array($keywords) and count($keywords)>0){
|
68
|
+
|
69
|
+
$sql.="AND (0 ";
|
70
|
+
|
71
|
+
foreach(["id","name"] as $v1){
|
72
|
+
|
73
|
+
$sql.=str_repeat("OR $v1 LIKE CONCAT('%',?,'%') ",count($keywords));
|
74
|
+
|
75
|
+
$data=array_merge($data,$keywords);
|
76
|
+
|
77
|
+
}
|
78
|
+
|
79
|
+
$sql.=") ";
|
80
|
+
|
81
|
+
}
|
82
|
+
|
83
|
+
```
|
84
|
+
|
85
|
+
- その2
|
86
|
+
|
87
|
+
```PHP
|
88
|
+
|
89
|
+
if($keyword!=="" and is_array($keywords) and count($keywords)>0){
|
90
|
+
|
91
|
+
$sql.="AND (0 ";
|
92
|
+
|
93
|
+
foreach(["id","name"] as $v1){
|
94
|
+
|
95
|
+
$sql.="OR $v1 REGEXP CONCAT(".implode(",'|',",array_fill(0,count($keywords),"?")).") ";
|
96
|
+
|
97
|
+
$data=array_merge($data,$keywords);
|
98
|
+
|
99
|
+
}
|
100
|
+
|
101
|
+
$sql.=") ";
|
102
|
+
|
103
|
+
}
|
104
|
+
|
105
|
+
```
|
1
調整
test
CHANGED
@@ -24,7 +24,7 @@
|
|
24
24
|
|
25
25
|
$sql = "SELECT * FROM table WHERE 1 ";
|
26
26
|
|
27
|
-
if(is_array($keywords) and count($keywords)>0){
|
27
|
+
if($keyword!=="" and is_array($keywords) and count($keywords)>0){
|
28
28
|
|
29
29
|
$sql.="AND (0 ";
|
30
30
|
|