/ Published in: PHP

PHP pagination simple algorithms;
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
total_page = 10; $previous_page = $current_page - 1; $next_page = $current_page + 1; if ($previous_page == 0) { $previous_page = 1; } if ($next_page > $total_page) { $next_page = $current_page; } echo "<a href='test.php?page=1'> First Page </a>"; echo "<a href='test.php?page=$previous_page'> Previous </a>"; for ($i=1; $i < $total_page; $i++) : if ($current_page == $i) { echo "<a href='test.php?page=$i'> $i - Selected </a>"; }else{ echo "<a href='test.php?page=$i'> $i </a>"; } endfor; echo "<a href='test.php?page=$total_page'> Last Page </a>"; echo "<a href='test.php?page=$next_page'> Next </a>";
Comments
