From 86cc0f63172b4ee6e6cfbe522e51b91b3c3463e5 Mon Sep 17 00:00:00 2001 From: ghost Date: Sat, 7 Aug 2021 17:44:29 +0300 Subject: [PATCH] fix pagination on search action --- library/mysql.php | 4 +++- public/index.php | 10 +++++----- public/index.phtml | 2 +- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/library/mysql.php b/library/mysql.php index 4b7bbb2..fa9c3b3 100755 --- a/library/mysql.php +++ b/library/mysql.php @@ -116,7 +116,9 @@ class MySQL { AND `data`.`ns` = "0" AND `data`.`deleted` = "0" - ORDER BY `block`.`blockId` DESC'); + ORDER BY `block`.`blockId` DESC + + LIMIT ' . (int) $start . ',' . (int) $limit); $query->bindValue(':search', '%' . $search . '%', PDO::PARAM_STR); diff --git a/public/index.php b/public/index.php index c9e2111..7761b0c 100755 --- a/public/index.php +++ b/public/index.php @@ -4,7 +4,7 @@ require_once('../config.php'); require_once('../library/icon.php'); require_once('../library/mysql.php'); -$query = isset($_GET['q']) && mb_strlen($_GET['q']) > 2 ? $_GET['q'] : false; +$query = isset($_GET['q']) ? $_GET['q'] : false; $ns = isset($_GET['ns']) ? preg_replace('/[^a-zA-Z0-9]+/', '', $_GET['ns']) : false; $tx = isset($_GET['tx']) ? preg_replace('/[^a-zA-Z0-9]+/', '', $_GET['tx']) : false; $page = (int) isset($_GET['page']) ? $_GET['page'] : 0; @@ -82,17 +82,17 @@ if (SEF_MODE) { $newer = false; } else { if ($page == 2) { - $newer = ($ns ? '?ns=' . $ns : ''); + $newer = ($ns ? '?ns=' . $ns : ($query ? '?q=' . $query : '')); } else { - $newer = ($ns ? '?ns=' . $ns . '&page=' . ($page - 1) : '?page=' . ($page - 1)); + $newer = ($ns ? '?ns=' . $ns . '&page=' . ($page - 1) : '?page=' . ($page - 1) . ($query ? '&q=' . $query : '')); } } if ($data) { if (in_array($page, [0, 1])) { - $older = ($ns ? '?ns=' . $ns . '&page=2' : '?page=2'); + $older = ($ns ? '?ns=' . $ns . '&page=2' : '?page=2' . ($query ? '&q=' . $query : '')); } else { - $older = ($ns ? '?ns=' . $ns . '&page=' . ($page + 1) : '?page=' . ($page + 1)); + $older = ($ns ? '?ns=' . $ns . '&page=' . ($page + 1) : '?page=' . ($page + 1) . ($query ? '&q=' . $query : '')); } } else { $older = false; diff --git a/public/index.phtml b/public/index.phtml index 863f94b..7aac6ff 100755 --- a/public/index.phtml +++ b/public/index.phtml @@ -86,7 +86,7 @@
- +