質問編集履歴

1

改修コードの貼り付け

2018/03/16 02:42

投稿

ShujiYamagami
ShujiYamagami

スコア7

test CHANGED
File without changes
test CHANGED
@@ -153,3 +153,99 @@
153
153
  ご教示お願いできますでしょうか。
154
154
 
155
155
  よろしくお願い致します。
156
+
157
+
158
+
159
+
160
+
161
+ 【追記】
162
+
163
+ 変更後コード
164
+
165
+ ```php
166
+
167
+ $select_sql = 'select cate01.parent_category_ids as cate1, cate02.parent_category_ids as cate2, t_salon.salon_cate02, t_salon.id, t_salon.salon_name, t_salon.salon_address, t_salon.salon_tel, t_salon.salon_latitude, t_salon.salon_longitude,
168
+
169
+ (6371 * ACOS(
170
+
171
+ COS(RADIANS(:lat))
172
+
173
+ * COS(RADIANS(salon_latitude))
174
+
175
+ * COS(RADIANS(`salon_longitude`) - RADIANS(:lng))
176
+
177
+ + SIN(RADIANS(:lat))
178
+
179
+ * SIN(RADIANS(salon_latitude))
180
+
181
+ )) AS distance
182
+
183
+ from t_salon
184
+
185
+ left join t_parent_category as cate01 on t_salon.salon_cate01 = cate01.id
186
+
187
+ left join t_parent_category as cate02 on t_salon.salon_cate02 = cate02.id
188
+
189
+ where cate01.parent_category_face = :treatment_id
190
+
191
+ having
192
+
193
+ distance <= :radius_val
194
+
195
+ order by
196
+
197
+ distance';
198
+
199
+
200
+
201
+
202
+
203
+
204
+
205
+ try {
206
+
207
+ $data = $pdo->prepare($select_sql);
208
+
209
+ # bind処理
210
+
211
+ $data->bindParam(':lat', $lat, PDO::PARAM_DECIMAL);
212
+
213
+ $data->bindParam(':lng', $long, PDO::PARAM_DECIMAL);
214
+
215
+ $data->bindParam(':treatment_id', $treatment_id, PDO::PARAM_STR);
216
+
217
+ $data->bindParam(':radius_val', $radius_val, PDO::PARAM_STR);
218
+
219
+
220
+
221
+ $data->execute();
222
+
223
+ if(!$data) {
224
+
225
+ echo "\nPDO::errorInfo():\n";
226
+
227
+ print_r($pdo->errorInfo());
228
+
229
+ exit;
230
+
231
+ return false;
232
+
233
+ }
234
+
235
+ $array = [];
236
+
237
+ while($row = $data -> fetch(PDO::FETCH_ASSOC)) {
238
+
239
+ $array[] = $row;
240
+
241
+ }
242
+
243
+ return $array;
244
+
245
+ } catch (PDOException $e) {
246
+
247
+ exit('データベースエラー : '.$e->getMessage());
248
+
249
+ }
250
+
251
+ ```