Add sortBy filter
This commit is contained in:
@@ -5,6 +5,7 @@ checkClientDatabaseVersion();
|
|||||||
$conn = newConnection();
|
$conn = newConnection();
|
||||||
|
|
||||||
$post = getPostData();
|
$post = getPostData();
|
||||||
|
$sortBy = (int)$post['sortBy'] ?? 2;
|
||||||
$priceRangeEnabled = (bool)$post['priceRangeEnabled'] ?? false;
|
$priceRangeEnabled = (bool)$post['priceRangeEnabled'] ?? false;
|
||||||
$priceRangeMin = (int)$post['priceRangeMin'] ?? 10;
|
$priceRangeMin = (int)$post['priceRangeMin'] ?? 10;
|
||||||
$priceRangeMax = (int)$post['priceRangeMax'] ?? 250;
|
$priceRangeMax = (int)$post['priceRangeMax'] ?? 250;
|
||||||
@@ -14,6 +15,12 @@ $searchForValue = (string)$post['searchForValue'] ?? '';
|
|||||||
$where = ["u.banned = 0", "(c.state = 1 OR c.state = 2)"];
|
$where = ["u.banned = 0", "(c.state = 1 OR c.state = 2)"];
|
||||||
$params = [];
|
$params = [];
|
||||||
$types = "";
|
$types = "";
|
||||||
|
$order = match($sortBy) {
|
||||||
|
1 => "ORDER BY c.price ASC",
|
||||||
|
2 => "ORDER BY c.id ASC",
|
||||||
|
3 => "ORDER BY c.id DESC",
|
||||||
|
default => "ORDER BY c.price DESC",
|
||||||
|
};
|
||||||
|
|
||||||
if ($priceRangeEnabled) {
|
if ($priceRangeEnabled) {
|
||||||
$where[] = "c.price BETWEEN ? AND ?";
|
$where[] = "c.price BETWEEN ? AND ?";
|
||||||
@@ -33,7 +40,7 @@ $sql = "
|
|||||||
FROM marketplaceicons c
|
FROM marketplaceicons c
|
||||||
JOIN users u ON c.userId = u.id
|
JOIN users u ON c.userId = u.id
|
||||||
WHERE " . implode(" AND ", $where) . "
|
WHERE " . implode(" AND ", $where) . "
|
||||||
ORDER BY c.id ASC
|
$order
|
||||||
";
|
";
|
||||||
|
|
||||||
$stmt = $conn->prepare($sql);
|
$stmt = $conn->prepare($sql);
|
||||||
|
|||||||
Reference in New Issue
Block a user