From f06cef55e830037913b4284fcaefdea867a896c2 Mon Sep 17 00:00:00 2001 From: Subhamoy Biswas Date: Thu, 16 Nov 2023 22:21:47 +0530 Subject: [PATCH] (feat): added basic project search logic --- htdocs/core/handle_search.php | 3 ++- htdocs/core/query_functions.php | 11 +++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/htdocs/core/handle_search.php b/htdocs/core/handle_search.php index cadc339..4b5a2f9 100644 --- a/htdocs/core/handle_search.php +++ b/htdocs/core/handle_search.php @@ -5,7 +5,8 @@ require 'query_functions.php'; if ($_SERVER['REQUEST_METHOD'] === 'POST') { if (isset($_POST['keyword'])) { $keyword = $_POST['keyword']; - echo json_encode(array("keyword-recived" => $keyword)); + $results = fetch_search_results($conn, $keyword); + echo json_encode($results); } } ?> \ No newline at end of file diff --git a/htdocs/core/query_functions.php b/htdocs/core/query_functions.php index c642008..332b704 100644 --- a/htdocs/core/query_functions.php +++ b/htdocs/core/query_functions.php @@ -50,4 +50,15 @@ function fetch_social_icon($conn, $platform_name) { return $row['icon']; } } + +function fetch_search_results($conn, $keyword) { + $sql = "SELECT * FROM projects WHERE name LIKE '%$keyword%'"; + $result = $conn -> query($sql); + if($result -> num_rows > 0) { + return mysqli_fetch_all($result, MYSQLI_ASSOC); + } + else { + return array('results' => 'none'); + } +} ?> \ No newline at end of file