Как реализовать фильтр вывода информации таблицы mysql проще

Всем привет. У меня несколько фильтров в таблице срм. И что бы они все работали и работали вместе мне не обходимо прописывать кучу условий. Пример:

// ЕСЛИ ПОЛЯ ТИПА И ВРЕМЕНИ ЗАПОЛНЕНЫ ЮЗЕРОМ
if ($_SESSION['type_event'] != "none" && $_SESSION['where_data'] != "none" && $_SESSION['type_status'] != "none") {
    if ($_SESSION['type_status'] == "не выполнено") {
        $table = mysqli_query($connect, "SELECT * FROM `business_client` WHERE `status` IS NULL AND `type` = '$type_event' AND `data` = '$where_data' ");
        $table = mysqli_fetch_all($table);
        foreach ($table as $y) {
            require 'style/checkbox.php';
        }
    }
    $table = mysqli_query($connect, "SELECT * FROM `business_client` WHERE `data` = '$where_data' AND `type` = '$type_event' AND `status` = '$type_status'");
    $table = mysqli_fetch_all($table);
    foreach ($table as $y) {
        require 'style/checkbox.php';
    }
    // ЕСЛИ ПОЛЕ ТИП ЗАПОЛНЕНО А ПОЛЕ ВРЕМЯ И ПОЛЕ СТАТУС НЕТ 
} elseif ($_SESSION['type_event'] != "none" && $_SESSION['where_data'] == "none" && $_SESSION['type_status'] == "none") {
    $table = mysqli_query($connect, "SELECT * FROM `business_client` WHERE `type` = '$type_event'");
    $table = mysqli_fetch_all($table);
    foreach ($table as $y) {
        require 'style/checkbox.php';
    }
    // ЕСЛИ ПОЛЕ ТИП И ПОЛЕ СТАТУС ЗАПОЛНЕНО А ПОЛЕ ВРЕМЯ  НЕТ 
} elseif ($_SESSION['type_event'] != "none" && $_SESSION['where_data'] == "none" && $_SESSION['type_status'] != "none") {
    if ($_SESSION['type_status'] == "не выполнено") {
        $table = mysqli_query($connect, "SELECT * FROM `business_client` WHERE `status` IS NULL AND `type` = '$type_event' ");
        $table = mysqli_fetch_all($table);
        foreach ($table as $y) {
            require 'style/checkbox.php';
        }
    }
    $table = mysqli_query($connect, "SELECT * FROM `business_client` WHERE `type` = '$type_event' AND `status` = '$type_status'");
    $table = mysqli_fetch_all($table);
    foreach ($table as $y) {
        require 'style/checkbox.php';
    }
    // ЕСЛИ ПОЛЕ ТИП И ПОЛЕ ДАТА ЗАПОЛНЕНО А ПОЛЕ СТАТУС  НЕТ 
} elseif ($_SESSION['type_event'] != "none" && $_SESSION['where_data'] != "none" && $_SESSION['type_status'] == "none") {
    $table = mysqli_query($connect, "SELECT * FROM `business_client` WHERE `type` = '$type_event' AND `data` = '$where_data'");
    $table = mysqli_fetch_all($table);
    foreach ($table as $y) {
        require 'style/checkbox.php';
    }
    // ЕСЛИ ПОЛЕ ТИП НЕ ЗАПОЛНЕНО, А ДАТА И СТАТУС ЗАПОЛНЕЫ 
} elseif ($_SESSION['type_event'] == "none" && $_SESSION['where_data'] != "none" && $_SESSION['type_status'] != "none") {
    if ($_SESSION['type_status'] == "не выполнено") {
        $table = mysqli_query($connect, "SELECT * FROM `business_client` WHERE `status` IS NULL AND `data` = '$where_data' ");
        $table = mysqli_fetch_all($table);
        foreach ($table as $y) {
            require 'style/checkbox.php';
        }
    }
    $table = mysqli_query($connect, "SELECT * FROM `business_client` WHERE `data` = '$where_data' AND `status` = '$type_status'");
    $table = mysqli_fetch_all($table);
    foreach ($table as $y) {
        require 'style/checkbox.php';
    }
    // ЕСЛИ ПОЛЯ НЕ ЗАПОЛНЕНЫ 
} elseif ($_SESSION['type_event'] == "none" && $_SESSION['where_data'] == "none" && $_SESSION['type_status'] == "none") {
    $table = mysqli_query($connect, "SELECT * FROM `business_client`");
    $table = mysqli_fetch_all($table);
    foreach ($table as $y) {
        require 'style/checkbox.php';
    }
    // ЕСЛИ ПОЛЯ ТИП И ДАТА НЕ ЗАПОЛНЕНЫ, А ПОЛЕ СТАТУС ЗАПОЛНЕНО 
} elseif ($_SESSION['type_event'] == "none" && $_SESSION['where_data'] == "none" && $_SESSION['type_status'] != "none") {
    if ($_SESSION['type_status'] == "не выполнено") {
        $table = mysqli_query($connect, "SELECT * FROM `business_client` WHERE `status` IS NULL");
        $table = mysqli_fetch_all($table);
        foreach ($table as $y) {
            require 'style/checkbox.php';
        }
    }
    $table = mysqli_query($connect, "SELECT * FROM `business_client` WHERE `status` = '$type_status'");
    $table = mysqli_fetch_all($table);
    foreach ($table as $y) {
        require 'style/checkbox.php';
    }
    // ЕСЛИ ПОЛЯ ТИП И СТАТУС НЕ ЗАПОЛНЕНЫ, А ПОЛЕ ДАТА ЗАПОЛНЕНО 
} elseif ($_SESSION['type_event'] == "none" && $_SESSION['where_data'] != "none" && $_SESSION['type_status'] == "none") {
    $table = mysqli_query($connect, "SELECT * FROM `business_client` WHERE `data` = '$where_data'");
    $table = mysqli_fetch_all($table);
    foreach ($table as $y) {
        require 'style/checkbox.php';
    }
}

  

И это всего 3 фильтра, время статус и тип. Но мне как минимум еще 2 надо добавить. Соответственно количество этих условий, если я буду писать этим же методом, увеличиться до 24. Возможно ли какое то решение более простое?


Ответы (0 шт):