Limiting pagination links
Posted: Sat Oct 15, 2011 7:03 am
I've currently set up a pagination but I can't seem to figure out how I can limit the links shown because an overload of data crowds the pagination navigation. If there's over 30 pages, the pagination navigation looks way too cluttered. How can I adjust my current code so after 5 pages there's an ellipsis (...) and the link to the very last page after the ellipsis. Kind of like the way this forum's pagination is set up.
Code: Select all
if(!isset($_GET['page'])) {
$page = 1;
} else {
$page = (int)$_GET['page'];
}
$from = (($page * $total_questions) - $total_questions);
$result = mysql_query("SELECT * FROM $db_table WHERE answer != '' ORDER BY dateasked DESC LIMIT $from, $total_questions");
$count_unanswered = mysql_query("SELECT * FROM Ask WHERE answer!=''");
$unanswered = mysql_num_rows($count_unanswered);
if ($unanswered > 0) {
while($row = mysql_fetch_array($result)) {
$getdate = $row['dateasked'];
$getquestion = $row['question'];
$getanswer = $row['answer'];
echo "<div class='question'>";
echo "<b>Q: $getquestion</b><br>";
echo "A: $getanswer";
echo "</div>";
}
$total_results = mysql_fetch_array(mysql_query("SELECT COUNT(*) as num FROM $db_table WHERE answer != ''"));
$total_pages = ceil($total_results['num'] / $total_questions);