Greetings,
I'm doing a program and I want the same to have different types of queries to the database, because they asked me to do the following types of questions:
- Search by cedula
- Search by name
- Search for diseases
- Search by date range (Between two dates or only one)
I already have the model of how to make the query but only for a single type of parameter, in this case by the name of the person, but I would like to know how I can make different types of queries and most importantly by date range.
What I have in my mind is to put a SELECT where I ask for the method I want to search for and that parameter takes it to do the search but I have no idea how to do it.
Could someone throw me a cable?
I leave the code I have.
NOTE : Also when making these queries I need to pull data from two different tables, one called basic data and another one called medical data
<?php
function ejecuta_consulta($labusqueda){
include("conexiond.php");
$conexion= mysqli_connect($db_host,$db_usuario,$db_contra);
if(mysqli_connect_errno()){
echo "Fallo al conectar con la base de datos";
exit();
}
mysqli_select_db($conexion,$db_nombre) or die ("No se encuentra la base de datos.");
$consulta = "SELECT * FROM DATOSBASICOS WHERE NOM_PAC LIKE '%$labusqueda%'";
$resultados = mysqli_query($conexion,$consulta);
while($fila=mysqli_fetch_array($resultados, MYSQLI_ASSOC)){
echo $fila ['CED_PAC']. " ";
echo $fila ['NOM_PAC']. " ";
echo $fila ['APE_PAC']. " ";
echo $fila ['TEL_PAC']. " ";
echo $fila ['CEL_PAC']. " ";
echo "<br> ";
echo "<br> ";
}
mysqli_close($conexion);
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Sistema de historias médicas - Dr. Darling Davila</title>
<meta charset="utf-8">
<link rel="stylesheet" href="css/bootstrap.css">
<link rel="stylesheet" type="text/css" href="css/estilo.css">
<link href="https://fonts.googleapis.com/css?family=Lato|Roboto" rel="stylesheet">
</head>
<body>
<?php
$mibusqueda=$_GET["buscar"];
$mipag=$_SERVER["PHP_SELF"];
if($mibusqueda!=NULL){
ejecuta_consulta($mibusqueda);
}else{
echo ("<form action='". $mipag . "' method='GET'>
<img src='imagenes/header.png'>
<h2>Busqueda de paciente</h2>
<div class='contenedor'>
<input type='text' name='buscar' class='input-100 text-center inline-block col-md-6 btn-enviar espacio-arriba'></label>
<input type='submit' name='enviando' value='Consulta' class='text-center inline-block col-md-12 espacio-arriba btn-enviar'>
</div>
</form>");
}
?>
</body>
</html>
ANNEX:
I leave photos of my two tables