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;