how do i do a hyperlink to last page?

this is a page url..
e.g.


how do i do a hyperlink to last page not specific page..

Dani AI

Generated

Building on and : the reliable way is to count the total rows for the topic, divide by items per page and round up to get the last page number, then build a safe URL. Use a prepared query for the count, force integers for math, and escape the output. When assembling the link, use a proper query string (use & between parameters, not a second ?), or use http_build_query() so parameters are encoded correctly.

Example (PDO):

<?php
// $pdo = PDO instance, $topic_id and $per_page defined earlier
$stmt = $pdo->prepare('SELECT COUNT(*) FROM posts WHERE topic_id = ?');
$stmt->execute([$topic_id]);
$total = (int) $stmt->fetchColumn();

$per_page = max(1, (int) $per_page);
$last_page = (int) ceil($total / $per_page);
if ($last_page < 1) $last_page = 1;

$query = http_build_query(['id' => $topic_id, 'page' => $last_page]);
$url = 'topic.php?' . $query;

echo '<a href="' . htmlspecialchars($url, ENT_QUOTES, 'UTF-8') . '">Last page</a>';
?>

Notes: clamp inputs to integers, ensure $per_page > 0, and treat zero rows as page 1. For very large tables, COUNT(*) can be slow; consider keeping a per-topic counter that you update on insert/delete. Use ceil() for the math and http_build_query() to construct the query string safely.

Recommended Answers

All 2 Replies

Run a PHP database count...
Then, just echo out a link with the last page id.
Is this a pre-built application, or custom application?

hi..

if u have the page nos. stored in the database..

u can just query it, n take the last no.

then create a link out of it, where u need it..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.