November 26, 200916 yr Ok so i built this simple php pagination script people can use if you find this post useful and enjoy my work please give me a +1. <?php mysql_connect("localhost","root","") or die (mysql_error()); mysql_select_db(yourtable); $page = (!$_GET['page'] || $_GET['page'] < 0) ? "1" : $_GET['page']; $page = ceil($page); $limit = 5; $start = $limit; $end = $page*$limit-($limit); $amount = "SELECT * FROM `yourtable`"; $amount2 = mysql_query($amount) or die(mysql_error()); $amount3 = mysql_num_rows($amount2); $pages = ceil($amount3/$limit); $previous = ($page-1 <= 0) ? "« Prev" : "<a href=\"./yourpage.php?page=".($page-1)."\">« Prev</a>"; $nextpage = ($page+1 > $pages) ? "Next »" : "<a href=\"./yourpage.php?page=".($page+1)."\">Next »</a>"; echo $previous; for($i=1;$i<=$pages;$i++){ $href = ($page == $i) ? " ".$i." " : " <a href=\"./yourpage.php?page=".$i."\">".$i."</a> "; echo $href; } echo $nextpage; ?> Hope you find it useful cheers
Create an account or sign in to comment