Я работаю в приложении геолокации и хочу вернуть результат радиуса в соответствии с тегами пользователя
$tags = preg_replace('/\s+/', '', $tags);
$tags_list = [];
$tags_list = explode(',', $tags);
$tags = implode(" OR c.title=", $tags_list);
echo $tags;
if(
!empty($latitude) &&
!empty($longtitude) &&
!empty($radius)
){
$qry = "SELECT o.id, o.title, o.icon, o.description,
(
6371 * acos
(
cos(
radians( :lat )
)
* cos(
radians( lat)
) * cos(
radians( lng) - radians( :lng )
) + sin(
radians( :lat )
) * sin(
radians( lat)
)
)
) AS distance
FROM objects o, category_object co, category c
WHERE o.id = co.id_object AND co.id_category = c.id AND c.title=:title
HAVING distance/1000 <= :radius
ORDER BY distance/1000 ASC;";
$stmt = $db->prepare($qry);
$stmt->bindParam(":lat", $latitude);
$stmt->bindParam(":lng", $longtitude);
//Here
$stmt->bindParam(":title", $tags);
$stmt->bindParam(":radius", $radius);
if($stmt->execute()){
while ($result = $stmt->fetch(PDO::FETCH_OBJ)) {
echo json_encode(array("type" => "FeatureCollection",
"features" => array(
"type" => "Feature",
"geometry" => array("type" => "Point",
"coordinates" => [$latitude, $longtitude]),
"properties" => array(
"ID" => $result->id,
"icon" => $result->icon,
"tags" => "",
"title" => $result->title,
"description" => $result->description))), JSON_UNESCAPED_SLASHES);
echo "\n\n";
}
}
Если я введу "мексиканец", он отлично работает.
localhost/../radius.php&lat=..&lng=..&radius=..&tags=mexican <<<-- works
Проблема в том, что когда я ввожу
localhost/../radius.php&lat=..&lng=..&radius=..&tags=mexican,restaurants <<<-- doesn't work
Я думаю, проблема в том, что я преобразую код в заранее подготовленное утверждение, поэтому я хотел бы знать, как изменить способ его ввода.
Спасибо за потраченное время!
Код подключения к БД
<?php
class Database {
public function getConnection() {
$this->conn = null;
try {
$this->conn = new PDO("mysql:host=" . $this->host . ";dbname=" . $this->db_name, $this->username, $this->password);
$this->conn->exec("set names utf8");
} catch (PDOException $e) {
echo "connection error" . $e->getMessage();
}
return $this->conn;
}
}
?>