class Test{
/**
* @param string $e
* @throws Exception
*/
public function error($e){
throw new Exception($e);
}
public function run(){
$this->error('fatal-error');
}
}
try{
$a = new Test();
$a->run();
}catch(Exception $e){
echo $e->getMessage();
}
$this-><b>error</b>('fatal-error');
$query = "SELECT * FROM `tab`";
$where = [];
if(!empty($_POST['size_1']) && !empty($_POST['size_2']) && $_POST['size_2'] > $_POST['size_1']){
$where[] = "`size` BETWEEN ".$_POST['size_1']." AND ".$_POST['size_2']."";
}elseif(!empty($_POST['size_1'])){
$where[] = "`size` >= ".$_POST['size_1'];
}elseif(!empty($_POST['size_2'])){
$where[] = "`size` <= ".$_POST['size_2'];
}
if(!empty($_POST['price_1']) && !empty($_POST['price_2']) && $_POST['price_2'] >= $_POST['price_1']){
$where[] = "`price` BETWEEN ".$_POST['price_1']." AND ".$_POST['price_2']."";
}elseif(!empty($_POST['price_1'])){
$where[] = "`price` >= ".$_POST['size_1'];
}elseif(!empty($_POST['price_2'])){
$where[] = "`price` <= ".$_POST['price_2'];
}
if(!empty($where)){
$query .= implode(' AND ', $where);
}
echo $query;
<form method="post">
маленький <input type="radio" name="cake_size" value="1" checked><br><br>
большой <input type="radio" name="cake_size" value="2"><br><br>
средний <input type="radio" name="cake_size" value="3"><br><br>
<input type="submit">
</form>
$cake_size = 'Размер торта не определен';
if(!empty($_POST['cake_size'])){
if($_POST['cake_size'] == 1){
$cake_size = 'маленький';
}elseif($_POST['cake_size'] == 2){
$cake_size = 'большой';
}elseif($_POST['cake_size'] == 3){
$cake_size = 'средний';
}
}
echo $cake_size;