mirror of
https://github.com/neosubhamoy/neosubhamoy-portfolio.git
synced 2025-12-19 23:59:35 +05:30
(refactor): implemented object,array based search result categories and multi table search on backend and frontend
This commit is contained in:
@@ -7,8 +7,20 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$keyword = $_POST['keyword'];
|
||||
$results_projects = fetch_search_results_projects($conn, $keyword);
|
||||
$results_socials = fetch_search_results_socials($conn, $keyword);
|
||||
$results = array_merge($results_projects, $results_socials);
|
||||
echo json_encode($results);
|
||||
|
||||
$results = [];
|
||||
foreach ([$results_projects, $results_socials] as $array) {
|
||||
if (!empty($array)) {
|
||||
$results = array_merge($results, $array);
|
||||
}
|
||||
}
|
||||
|
||||
if(!empty($results)) {
|
||||
echo json_encode($results);
|
||||
}
|
||||
else {
|
||||
echo json_encode(array('results' => 'none', 'message' => ': ( No Results Found'));
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -51,6 +51,8 @@ function fetch_social_icon($conn, $platform_name) {
|
||||
}
|
||||
}
|
||||
|
||||
//---functions to fetch search results starts here---
|
||||
//from projects table
|
||||
function fetch_search_results_projects($conn, $keyword) {
|
||||
$sql = "SELECT * FROM projects WHERE name LIKE '%$keyword%'";
|
||||
$result = $conn -> query($sql);
|
||||
@@ -62,10 +64,11 @@ function fetch_search_results_projects($conn, $keyword) {
|
||||
return $result;
|
||||
}
|
||||
else {
|
||||
return array('results' => 'none', 'message' => ': ( No Results Found');
|
||||
return array();
|
||||
}
|
||||
}
|
||||
|
||||
//from socials table
|
||||
function fetch_search_results_socials($conn, $keyword) {
|
||||
$sql = "SELECT * FROM socials WHERE platform LIKE '%$keyword%'";
|
||||
$result = $conn -> query($sql);
|
||||
@@ -77,7 +80,7 @@ function fetch_search_results_socials($conn, $keyword) {
|
||||
return $result;
|
||||
}
|
||||
else {
|
||||
return array('results' => 'none', 'message' => ': ( No Results Found');
|
||||
return array();
|
||||
}
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user