Add Full text search

This commit is contained in:
Clément Fouché
2024-04-17 16:46:32 +02:00
parent 1dd66ceac8
commit 7c3289e266

View File

@@ -4,8 +4,9 @@ require_once '../API/src/response.php';
// searchDoctor search doctor by name or specialty and return the result in JSON format
function searchDoctor($pdo, $type): void
{
$query = $pdo->prepare("SELECT m_name, m_surname, m_postal, m_specialty, m_phone, m_id FROM medecin WHERE m_specialty = :type");
$query->bindParam(':type', $type);
$queryvar = "%".$type."%";
$query = $pdo->prepare("SELECT m_name, m_surname, m_postal, m_specialty, m_phone, m_id FROM medecin WHERE m_specialty ILIKE :type");
$query->bindParam(':type', $queryvar);
$query->execute();
$result = $query->fetchAll();
// Check if the query returned any result
@@ -14,8 +15,8 @@ function searchDoctor($pdo, $type): void
$count++;
}
if($count == 0){
$query = $pdo->prepare("SELECT m_name, m_surname, m_postal, m_specialty, m_phone, m_id FROM medecin WHERE m_name = :type");
$query->bindParam(':type', $type);
$query = $pdo->prepare("SELECT m_name, m_surname, m_postal, m_specialty, m_phone, m_id FROM medecin WHERE m_name ILIKE :type");
$query->bindParam(':type', $queryvar);
$query->execute();
$result = $query->fetchAll();
$count = 0;