我想自动化从数据库过滤数据的过程。 目前,我有四个过滤选项,可为我们提供十五种可能的事件。 十五个,因为可以组合过滤选项。
一个事件=一个事件。 如果有新的过滤选项,则必须更正所有先前的事件并创建一些新的事件。
请告诉我我可以做些什么,以使脚本知道应该根据所选过滤选项的数量生成什么SQL问题。
下面是缩短的代码,仅支持三个事件:
if((!empty($_POST['check_name'])) && (empty($_POST['medycznee'])) && (empty($_POST['check_fraze']))){
$check_name = $_POST['check_name'];
$sql_check_name = "SELECT * FROM procedures WHERE procedures.nameProcedure LIKE '%$check_name%'";
$result_sql = $connection->query($sql_check_name);
while($row = $result_sql->fetch_assoc()){
$name_procedure = $row['nameProcedure'];
$desc_procedure = $row['descProcedure'];
$type_procedure = $row['typeProcedure'];
$file_procedure = $row['fileProcedure'];
echo "Name of procedure: <b>" . $name_procedure . "</b><br>";
echo "Description of procedure: " . $desc_procedure . "<br>";
echo "Type of procedure: " . $type_procedure . "<br>";
echo "<a href=uploads/" . $file_procedure . ">Podejrzyj PDF</a><br>";
echo "-----------------------------------------------<br>";
}
$result_sql->free_result();
}// end if -> name
if((!empty($_POST['check_fraze'])) && (empty($_POST['check_name'])) && (empty($_POST['medycznee']))){
$check_fraze = $_POST['check_fraze'];
$sql_check_name = "SELECT * FROM procedures WHERE procedures.descProcedure LIKE '%$check_fraze%'";
$result_sql = $connection->query($sql_check_name);
while($row = $result_sql->fetch_assoc()){
$name_procedure = $row['nameProcedure'];
$desc_procedure = $row['descProcedure'];
$type_procedure = $row['typeProcedure'];
$file_procedure = $row['fileProcedure'];
echo "Name of procedure: <b>" . $name_procedure . "</b><br>";
echo "Description of procedure: " . $desc_procedure . "<br>";
echo "Type of procedure: " . $type_procedure . "<br>";
echo "<a href=uploads/" . $file_procedure . ">Podejrzyj PDF</a><br>";
echo "-----------------------------------------------<br>";
}
$result_sql->free_result();
}// end if -> fraze
if((!empty($_POST['check_fraze'])) && (!empty($_POST['check_name'])) && (empty($_POST['medycznee']))){
$check_fraze = $_POST['check_fraze'];
$check_name = $_POST['check_name'];
$sql_check_name_fraze = "SELECT * FROM procedures WHERE procedures.descProcedure LIKE '%$check_fraze%' AND procedures.nameProcedure LIKE '%$check_name%'";
$result_sql = $connection->query($sql_check_name_fraze);
while($row = $result_sql->fetch_assoc()){
$name_procedure = $row['nameProcedure'];
$desc_procedure = $row['descProcedure'];
$type_procedure = $row['typeProcedure'];
$file_procedure = $row['fileProcedure'];
echo "Name of procedure: <b>" . $name_procedure . "</b><br>";
echo "Description of procedure: " . $desc_procedure . "<br>";
echo "Type of procedure: " . $type_procedure . "<br>";
echo "<a href=uploads/" . $file_procedure . ">Podejrzyj PDF</a><br>";
echo "-----------------------------------------------<br>";
}
$result_sql->free_result();
}// end if -> fraze