From 7c3289e2666b1d2aa0ea190a2347e5ae1249bef2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fouch=C3=A9?= Date: Wed, 17 Apr 2024 16:46:32 +0200 Subject: [PATCH] Add Full text search --- src/php/db/Search.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/php/db/Search.php b/src/php/db/Search.php index 91c3c03..af60ba0 100644 --- a/src/php/db/Search.php +++ b/src/php/db/Search.php @@ -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;