$name = isset($_POST['name']) ? $_POST['name'] : null;
$description = isset($_POST['description']) ? $_POST['description'] : null;
$lalala = isset($_POST['lalala']) ? $_POST['lalala'] : null;
$dbh = new PDO('mysql:host=localhost', 'user', 'pass');
$stmt = $dbh->prepare("SELECT * FROM table_name where (name = ? or ?) and (description = ? or ?) and (lalala = ? or ?)");
$stmt->execute(array($name, is_null($name), $description, is_null($description), $lalala, is_null($lalala)));
foreach($stmt->fetchAll() as $row) {}
Для 15 параметров будет 15 строк?$name = isset($_POST['name']) ? $_POST['name'] : null;
$description = isset($_POST['description']) ? $_POST['description'] : null;
$lalala = isset($_POST['lalala']) ? $_POST['lalala'] : null;
Вы ведь с этим работали и готовый код наверняка есть.array($name, is_null($name),
$values = array_intersect_key($_POST, $fields) + $fields;
$stmt = $dbh->prepare("SELECT * FROM table_name where (name = :name or :name is null) and (description = :description or :description is null) and ..."); // можно склеивать в цикле, причем без всяких if'ов и без данных - запрос всегда один и тот же
$stmt->execute($values);
Автор оригинала: Вурдалак
PHP:$where_clause = empty($conditionList) ? '' : 'WHERE ' . implode(' AND ', $conditionList);
$conditionList=array();
if(isset($_GET['hotel'])!=""){
$hotel=$_GET['hotel'];
$conditionList[]="Hotel_id='$hotel'";
}
if(isset($_GET['nights'])!=""){
$nights=$_GET['nights'];
$conditionList[]="nights='$nights'";
}
$where= empty($conditionList) ? '' : 'WHERE ' . implode(' AND ', $conditionList);
print $where;
— http://www.php.net/manual/en/language.operators.phpв мане искать инфу про "?" и ":"
$conditionList=array();
$nights="nights='".$_GET['nights']."'";
$conditionList[]=empty($_GET['nights']) ? null : $nights;
$roomcat="roomCategory_id='".$_GET['roomcat']."'";
$conditionList[]= empty($_GET['roomcat']) ? null : $roomcat;
$conditionList=array_filter($conditionList);
$where= empty($conditionList) ? '' : 'WHERE ' . implode(' AND ', $conditionList);
SELECT name FROM Hotel WHERE id='$Hotel_id'
SELECT name FROM Tour WHERE id='$Tour_id'
откуда берутся эти *_id? сколько всего требуется узнать имён отелей, туров, и т.д. для вывода результатов поиска?Перед выводом на экран результатов поиска у меня есть (например) $Hotel_id, $Board_id, $Tour_id - а мне нужны $Hotel_name, $Board_name и т.д. которые лежат в других таблицах базы.