summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathan Kinkade <nath@nkinka.de>2013-11-26 23:30:29 +0000
committerNathan Kinkade <nath@nkinka.de>2013-11-26 23:30:29 +0000
commit544fd291b0f19012bee24b57cd3ccc1924deab8e (patch)
tree2bbc61a0bf56ff96195b6f33e2bbee93a5d1aa78
parent917f9f6602659fb5d0a859cb8035f808f7a0ecf5 (diff)
Dont' show the Next Page>> link if we are already viewing the last of the records.
-rw-r--r--search.php15
1 files changed, 9 insertions, 6 deletions
diff --git a/search.php b/search.php
index c2409c5..d2fdb71 100644
--- a/search.php
+++ b/search.php
@@ -275,7 +275,8 @@ if ( $_REQUEST['orderby'] && $_REQUEST['orderdir'] ) {
echo "<a id='search_again' href='/'>New Search</a>";
-# Get the total row count so we can display it to the user
+# Get the total row count so we can display it to the user and deal with
+# pagination
$st = $dbh->prepare($sql);
if ( $st->execute() ) {
$row_count = $st->rowCount();
@@ -288,7 +289,11 @@ if ( $st->execute() ) {
} elseif ( $_GET['page'] ) {
$viewing = ($_GET['page'] - 1) * $results_per_page + 1;
$upto = ($_GET['page'] - 1) * $results_per_page + $results_per_page;
- echo "<h3>Viewing {$viewing} to {$upto} of {$row_count} records found.</h3>";
+ if ( $upto >= $row_count ) {
+ echo "<h3>Viewing {$viewing} to {$row_count} of {$row_count} records found.</h3>";
+ } else {
+ echo "<h3>Viewing {$viewing} to {$upto} of {$row_count} records found.</h3>";
+ }
} else {
echo "<h3>Viewing 1 to {$results_per_page} of {$row_count} records found.</h3>";
}
@@ -385,15 +390,13 @@ HTML;
echo "</table>";
-if ( $_GET['page'] && $row_count > $results_per_page ) {
+if ( $_GET['page'] && $row_count > $results_per_page && $upto < $row_count ) {
$next_page = $_GET['page'] + 1;
echo "<br /><a href='search.php?{$_SERVER['QUERY_STRING']}&page={$next_page}'>Next Page&gt;&gt;</a>";
-} elseif ( $row_count > $results_per_page ) {
+} elseif ( $row_count > $results_per_page && $upto < $row_count ) {
echo "<br /><a href='search.php?{$_SERVER['QUERY_STRING']}&page=2'>Next Page &gt;&gt;</a>";
}
-echo "<div>$sql</div>";
-
echo <<<HTML
</body>