回答編集履歴
3
誤記の修正
test
CHANGED
@@ -104,7 +104,7 @@
|
|
104
104
|
|
105
105
|
if(stripos($i['name_ja'], $w) !== FALSE){ //←ここ
|
106
106
|
|
107
|
-
$b[] = $i;
|
107
|
+
$b[] = $i['name_ja'];
|
108
108
|
|
109
109
|
}
|
110
110
|
|
2
誤認識
test
CHANGED
@@ -46,106 +46,78 @@
|
|
46
46
|
|
47
47
|
######追記
|
48
48
|
|
49
|
-
参考までに当方の方で動作が確認できているソースを記載しておきます。(MySQL、FuelPHP)
|
49
|
+
~~参考までに当方の方で動作が確認できているソースを記載しておきます。(MySQL、FuelPHP)~~
|
50
50
|
|
51
51
|
|
52
52
|
|
53
|
-
|
53
|
+
見当違いの回答だったっぽいので不要なコードは消し消し。
|
54
54
|
|
55
|
-
|
55
|
+
恐らく以下が問題になっているのではないかと。
|
56
56
|
|
57
|
-
|
57
|
+
```PHP
|
58
58
|
|
59
|
-
|
59
|
+
if(isset($_POST['param1'])){
|
60
60
|
|
61
|
-
|
61
|
+
$w = $_POST['param1'];
|
62
62
|
|
63
|
+
foreach($list as $i){
|
64
|
+
|
65
|
+
if(stripos($i, $w) !== FALSE){ //←ここ
|
66
|
+
|
67
|
+
$b[] = $i;
|
68
|
+
|
69
|
+
}
|
70
|
+
|
71
|
+
}
|
72
|
+
|
73
|
+
echo json_encode($b);
|
74
|
+
|
75
|
+
}
|
76
|
+
|
77
|
+
else{
|
78
|
+
|
79
|
+
echo json_encode($b);
|
80
|
+
|
81
|
+
}
|
82
|
+
|
63
|
-
|
83
|
+
```
|
64
84
|
|
65
85
|
|
66
86
|
|
67
|
-
|
87
|
+
`$list`から取り出した要素`$i`は`array`なので、
|
68
88
|
|
69
|
-
|
89
|
+
ここで`$w`(=`$_POST['param1']`)との比較に失敗してしまっていると考えられます。
|
70
90
|
|
71
|
-
$records = DB::select('name')
|
72
91
|
|
73
|
-
->from('hoge')
|
74
92
|
|
75
|
-
|
93
|
+
コメントにも書きましたが以下のように変更すれば解消できるのではないでしょうか。
|
76
94
|
|
77
|
-
->distinct()
|
78
95
|
|
79
|
-
->execute($connect)->as_array();
|
80
96
|
|
81
|
-
|
97
|
+
```PHP
|
82
98
|
|
83
|
-
|
99
|
+
if(isset($_POST['param1'])){
|
84
100
|
|
85
|
-
|
101
|
+
$w = $_POST['param1'];
|
86
102
|
|
87
|
-
|
103
|
+
foreach($list as $i){
|
88
104
|
|
89
|
-
|
105
|
+
if(stripos($i['name_ja'], $w) !== FALSE){ //←ここ
|
106
|
+
|
107
|
+
$b[] = $i;
|
108
|
+
|
109
|
+
}
|
90
110
|
|
91
111
|
}
|
92
112
|
|
93
|
-
|
113
|
+
echo json_encode($b);
|
94
114
|
|
95
|
-
|
115
|
+
}
|
96
116
|
|
97
|
-
|
117
|
+
else{
|
98
118
|
|
119
|
+
echo json_encode($b);
|
120
|
+
|
99
|
-
|
121
|
+
}
|
100
122
|
|
101
123
|
```
|
102
|
-
|
103
|
-
html
|
104
|
-
|
105
|
-
```jQuery
|
106
|
-
|
107
|
-
$("#list").autocomplete({
|
108
|
-
|
109
|
-
source: function(req, resp){
|
110
|
-
|
111
|
-
$.ajax({
|
112
|
-
|
113
|
-
url: "<?php echo URI::base();?>/base/record/",
|
114
|
-
|
115
|
-
dataType: "json",
|
116
|
-
|
117
|
-
success: function (res){
|
118
|
-
|
119
|
-
if(!res.error){
|
120
|
-
|
121
|
-
let result = res.success;
|
122
|
-
|
123
|
-
resp(result);
|
124
|
-
|
125
|
-
}
|
126
|
-
|
127
|
-
},
|
128
|
-
|
129
|
-
error: function(xhr, textStatus, errorThrown) {
|
130
|
-
|
131
|
-
res([]);
|
132
|
-
|
133
|
-
}
|
134
|
-
|
135
|
-
});
|
136
|
-
|
137
|
-
},
|
138
|
-
|
139
|
-
delay: 500,
|
140
|
-
|
141
|
-
minLength:0,
|
142
|
-
|
143
|
-
autoFocus: false
|
144
|
-
|
145
|
-
}).focus(function(){
|
146
|
-
|
147
|
-
$(this).autocomplete("search", "");
|
148
|
-
|
149
|
-
});
|
150
|
-
|
151
|
-
```
|
1
追記
test
CHANGED
@@ -41,3 +41,111 @@
|
|
41
41
|
|
42
42
|
|
43
43
|
何れにせよ`o`の中身を見てみると良いかもです。
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
######追記
|
48
|
+
|
49
|
+
参考までに当方の方で動作が確認できているソースを記載しておきます。(MySQL、FuelPHP)
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
base.php
|
54
|
+
|
55
|
+
```FuelPHP
|
56
|
+
|
57
|
+
public function get_record(){
|
58
|
+
|
59
|
+
$headers = array(
|
60
|
+
|
61
|
+
'Content-type' => 'application/json',
|
62
|
+
|
63
|
+
);
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
$connect = Model_Hoge::connection();
|
68
|
+
|
69
|
+
try{
|
70
|
+
|
71
|
+
$records = DB::select('name')
|
72
|
+
|
73
|
+
->from('hoge')
|
74
|
+
|
75
|
+
->where('deleted_at',null)
|
76
|
+
|
77
|
+
->distinct()
|
78
|
+
|
79
|
+
->execute($connect)->as_array();
|
80
|
+
|
81
|
+
$result = array_values($records[0]);
|
82
|
+
|
83
|
+
}catch (Exception $e){
|
84
|
+
|
85
|
+
$error = array("error" => "検索に失敗しました");
|
86
|
+
|
87
|
+
$data = Format::forge($error)->to_json();
|
88
|
+
|
89
|
+
return Response::forge($data, 200, $headers);
|
90
|
+
|
91
|
+
}
|
92
|
+
|
93
|
+
$success = array("success" => $result);
|
94
|
+
|
95
|
+
$data = Format::forge($success)->to_json();
|
96
|
+
|
97
|
+
return Response::forge($data, 200, $headers);
|
98
|
+
|
99
|
+
}
|
100
|
+
|
101
|
+
```
|
102
|
+
|
103
|
+
html
|
104
|
+
|
105
|
+
```jQuery
|
106
|
+
|
107
|
+
$("#list").autocomplete({
|
108
|
+
|
109
|
+
source: function(req, resp){
|
110
|
+
|
111
|
+
$.ajax({
|
112
|
+
|
113
|
+
url: "<?php echo URI::base();?>/base/record/",
|
114
|
+
|
115
|
+
dataType: "json",
|
116
|
+
|
117
|
+
success: function (res){
|
118
|
+
|
119
|
+
if(!res.error){
|
120
|
+
|
121
|
+
let result = res.success;
|
122
|
+
|
123
|
+
resp(result);
|
124
|
+
|
125
|
+
}
|
126
|
+
|
127
|
+
},
|
128
|
+
|
129
|
+
error: function(xhr, textStatus, errorThrown) {
|
130
|
+
|
131
|
+
res([]);
|
132
|
+
|
133
|
+
}
|
134
|
+
|
135
|
+
});
|
136
|
+
|
137
|
+
},
|
138
|
+
|
139
|
+
delay: 500,
|
140
|
+
|
141
|
+
minLength:0,
|
142
|
+
|
143
|
+
autoFocus: false
|
144
|
+
|
145
|
+
}).focus(function(){
|
146
|
+
|
147
|
+
$(this).autocomplete("search", "");
|
148
|
+
|
149
|
+
});
|
150
|
+
|
151
|
+
```
|