Skip to content
Snippets Groups Projects
Commit c56f1219 authored by Hidayatullah Wildan Ghaly Buchary's avatar Hidayatullah Wildan Ghaly Buchary
Browse files

fix: fix bug on search, filter, sort of challenge

parent 427794f2
Branches
Tags
No related merge requests found
...@@ -31,7 +31,7 @@ $sql1 .= " LIMIT $start, $limit"; ...@@ -31,7 +31,7 @@ $sql1 .= " LIMIT $start, $limit";
$sql2 = "SELECT COUNT(id) AS id FROM quest"; $sql2 = "SELECT COUNT(id) AS id FROM quest";
if ($search !== '') { if ($search !== '') {
$sql2 .= " AND name LIKE '%$search%'"; $sql2 .= " WHERE $searchAttr LIKE '%$search%'";
} }
$result = $conn->query($sql1); $result = $conn->query($sql1);
......
...@@ -31,6 +31,7 @@ if (!isset($_SESSION['username'])) { ...@@ -31,6 +31,7 @@ if (!isset($_SESSION['username'])) {
<option value="id">ID</option> <option value="id">ID</option>
<option value="name">Name</option> <option value="name">Name</option>
<option value="description">Description</option> <option value="description">Description</option>
<option value="threshold">Threshold</option>
</select> </select>
</div> </div>
<div class="filter-sort-container"> <div class="filter-sort-container">
......
...@@ -8,23 +8,23 @@ document.addEventListener('DOMContentLoaded', function () { ...@@ -8,23 +8,23 @@ document.addEventListener('DOMContentLoaded', function () {
var page = urlParams.get("page"); var page = urlParams.get("page");
var achievementLimitCookie = document.cookie.split('; ').find(cookie => cookie.startsWith('collection-limit=')); var achievementLimitCookie = document.cookie.split('; ').find(cookie => cookie.startsWith('challenge-limit='));
var limit = achievementLimitCookie ? achievementLimitCookie.split('=')[1] : 5; var limit = achievementLimitCookie ? achievementLimitCookie.split('=')[1] : 5;
document.getElementById('page-limit').value = limit; document.getElementById('page-limit').value = limit;
var achievementSearchCookie = document.cookie.split('; ').find(cookie => cookie.startsWith('collection-search=')); var achievementSearchCookie = document.cookie.split('; ').find(cookie => cookie.startsWith('challenge-search='));
var search = achievementSearchCookie ? achievementSearchCookie.split('=')[1] : ""; var search = achievementSearchCookie ? achievementSearchCookie.split('=')[1] : "";
document.getElementById('searchInput').value = search; document.getElementById('searchInput').value = search;
var achievementSearchAttributeCookie = document.cookie.split('; ').find(cookie => cookie.startsWith('collection-search-type=')); var achievementSearchAttributeCookie = document.cookie.split('; ').find(cookie => cookie.startsWith('challenge-search-type='));
var searchType = achievementSearchAttributeCookie ? achievementSearchAttributeCookie.split('=')[1] : "name"; var searchType = achievementSearchAttributeCookie ? achievementSearchAttributeCookie.split('=')[1] : "name";
document.getElementById('search-attribute').value = searchType; document.getElementById('search-attribute').value = searchType;
var achievementSortCookie = document.cookie.split('; ').find(cookie => cookie.startsWith('collection-sort=')); var achievementSortCookie = document.cookie.split('; ').find(cookie => cookie.startsWith('challenge-sort='));
var sort = achievementSortCookie ? achievementSortCookie.split('=')[1] : "default"; var sort = achievementSortCookie ? achievementSortCookie.split('=')[1] : "default";
document.getElementById('sort-by').value = sort; document.getElementById('sort-by').value = sort;
var achievementOrderCookie = document.cookie.split('; ').find(cookie => cookie.startsWith('collection-order=')); var achievementOrderCookie = document.cookie.split('; ').find(cookie => cookie.startsWith('challenge-order='));
var order = achievementOrderCookie ? achievementOrderCookie.split('=')[1] : "asc"; var order = achievementOrderCookie ? achievementOrderCookie.split('=')[1] : "asc";
document.getElementById('sort-type').value = order; document.getElementById('sort-type').value = order;
...@@ -57,7 +57,7 @@ document.addEventListener('DOMContentLoaded', function () { ...@@ -57,7 +57,7 @@ document.addEventListener('DOMContentLoaded', function () {
if (!limit || limit === "null" || limit === "undefined") { if (!limit || limit === "null" || limit === "undefined") {
limit = 5; limit = 5;
} }
document.cookie = `collection-limit=${limit}; path=/` document.cookie = `challenge-limit=${limit}; path=/`
loadAchievementPage(1); loadAchievementPage(1);
}); });
...@@ -70,7 +70,7 @@ document.addEventListener('DOMContentLoaded', function () { ...@@ -70,7 +70,7 @@ document.addEventListener('DOMContentLoaded', function () {
} }
timeout = setTimeout(function () { timeout = setTimeout(function () {
document.cookie = `collection-search=${search}; path=/` document.cookie = `challenge-search=${search}; path=/`
loadAchievementPage(1); loadAchievementPage(1);
}, 500); }, 500);
}); });
...@@ -80,7 +80,7 @@ document.addEventListener('DOMContentLoaded', function () { ...@@ -80,7 +80,7 @@ document.addEventListener('DOMContentLoaded', function () {
if (!searchType || searchType === "null" || searchType === "undefined") { if (!searchType || searchType === "null" || searchType === "undefined") {
searchType = "a.name"; searchType = "a.name";
} }
document.cookie = `collection-search-type=${searchType}; path=/` document.cookie = `challenge-search-type=${searchType}; path=/`
loadAchievementPage(1); loadAchievementPage(1);
}); });
...@@ -89,7 +89,7 @@ document.addEventListener('DOMContentLoaded', function () { ...@@ -89,7 +89,7 @@ document.addEventListener('DOMContentLoaded', function () {
if (!sort || sort === "null" || sort === "undefined" || sort === "default") { if (!sort || sort === "null" || sort === "undefined" || sort === "default") {
sort = "default"; sort = "default";
} }
document.cookie = `collection-sort=${sort}; path=/` document.cookie = `challenge-sort=${sort}; path=/`
loadAchievementPage(1); loadAchievementPage(1);
}); });
...@@ -98,7 +98,7 @@ document.addEventListener('DOMContentLoaded', function () { ...@@ -98,7 +98,7 @@ document.addEventListener('DOMContentLoaded', function () {
if (!order || order === "null" || order === "undefined" || order === "default") { if (!order || order === "null" || order === "undefined" || order === "default") {
order = "default"; order = "default";
} }
document.cookie = `collection-order=${order}; path=/` document.cookie = `challenge-order=${order}; path=/`
loadAchievementPage(1); loadAchievementPage(1);
}); });
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment