Здравствуйте имеется SQL запрос:
SELECT id, region, autonom, area, city, city_2 FROM locality
WHERE ((region LIKE ? and autonom is null and area is null and city is null and city_2 is null)
or (city LIKE ? and city_2 is null)
or(city_2 LIKE ?))
По сути это запрос ищет по полному совпадению. Мне нужно чтобы, если значение содержало строку, то выдавало результат (используется %).
К какой части % можно приделать?
Я пробовал в SQL засунуть (?+%; ?+'%')
в bind_param засунуть ($query+'%')
Везде вылазиют ошибки.
Код
function getAllCities($query){
$stmt = $this->con->prepare("SELECT id, region, autonom, area, city, city_2 FROM locality WHERE ((region LIKE ? and autonom is null and area is null and city is null and city_2 is null) or (city LIKE ? and city_2 is null) or(city_2 LIKE ?))");
$stmt-> bind_param("sss", $query, $query, $query);
$stmt->execute();
$stmt->bind_result($id, $region, $autonom, $area, $city, $city_2);
$cities = array();
while($stmt->fetch()){
$temp = array();
$temp['id'] = $id;
$temp['region'] = $region;
$temp['autonom'] = $autonom;
$temp['area'] = $area;
$temp['city'] = $city;
$temp['city_2'] = $city_2;
array_push($cities, $temp);
}
return $cities;
}
Варианты: bind_param("sss", $query+'%', $query+'%', $query+'%');
- Не срабатывает %
region LIKE ?+'%' and.... - Fatal error: Call to a member function bind_param()
region LIKE ?+% and ..... Fatal error: Call to a member function bind_param()
bind_param("sss", $query+%, $query+%, $query+%) - syntax error
Все, что требуется изменить:
$stmt = $this->con->prepare("SELECT id, region, autonom, area, city, city_2 FROM locality WHERE ((region LIKE ? and autonom is null and area is null and city is null and city_2 is null) or (city LIKE ? and city_2 is null) or (city_2 LIKE ?))");
// требуется потому, что аргументы в `bind_param` передаются по ссылке
$query .= '%';
$stmt->bind_param("sss", $query, $query, $query);
Кофе для программистов: как напиток влияет на продуктивность кодеров?
Рекламные вывески: как привлечь внимание и увеличить продажи
Я очень новичок в php, опыт где-то недели в бэкенде и надеюсь мне не кинут помидоры, а помогут
делаю вывод товаров по категориям,но возникает ошибка
Разбираюсь с шифрованием (end-2-end)Не могу понять где хранить ключи или ключ
Для плагина нужно сделать функцию очистки бдСделал удаление постов: