Browse Source

fix pagination on search action

pull/1/head
ghost 3 years ago
parent
commit
86cc0f6317
  1. 4
      library/mysql.php
  2. 10
      public/index.php
  3. 2
      public/index.phtml

4
library/mysql.php

@ -116,7 +116,9 @@ class MySQL { @@ -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);

10
public/index.php

@ -4,7 +4,7 @@ require_once('../config.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) { @@ -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;

2
public/index.phtml

@ -86,7 +86,7 @@ @@ -86,7 +86,7 @@
<?php } ?>
<div class="t-center px-16 pb-27">
<form name="namespace" action="/" method="GET">
<input class="p-8" type="text" name="q" value="" placeholder="key, value, block, ns, txid" autocomplete="off" />
<input class="p-8" type="text" name="q" value="<?php echo ($query ? $query : ''); ?>" placeholder="key, value, block, ns, txid" autocomplete="off" />
<button class="p-8 cursor-pointer" type="submit">Search</button>
</form>
</div>

Loading…
Cancel
Save