AdRock Posted October 31, 2006 Share Posted October 31, 2006 Is it possible to edit this script so it displays like Google style paging where only a set number of page links are displayed at one time?[code]<? //REMEMBER TO CONNECT TO DATABASE! include_once("includes/connection.php");//**EDIT TO YOUR TABLE NAME, ECT. $t = mysql_query("SELECT * FROM `events`"); if(!$t) die(mysql_error()); $a = mysql_fetch_object($t); $total_items = mysql_num_rows($t); $limit = $_GET['limit']; $page = $_GET['pagenum']; //set default if: $limit is empty, non numerical, less than 1, greater than 50 if((!$limit) || (is_numeric($limit) == false) || ($limit < 1) || ($limit > 50)) { $limit = 1; //default } //set default if: $page is empty, non numerical, less than zero, greater than total available if((!$page) || (is_numeric($page) == false) || ($page < 0) || ($page > $total_items)) { $page = 1; //default } //calcuate total pages $total_pages = ceil($total_items / $limit); $set_limit = $page * $limit - ($limit); //query: **EDIT TO YOUR TABLE NAME, ECT. $q = mysql_query("SELECT id,title,content, DATE_FORMAT(eventdate, '%W %D %M %Y') as date, photo FROM events ORDER BY id DESC LIMIT $set_limit, $limit"); if(!$q) die(mysql_error()); $err = mysql_num_rows($q); if($err == 0) die("No matches met your criteria."); //Results per page: **EDIT LINK PATH** //show data matching query: while($code = mysql_fetch_array($q)) { $EventDate = $code['eventdate']; echo "<h3>".$code['title']."</h3><p class='style3' style='text-align:left'><i>Event date: <b>".$code['date']."</b></i></p><p class=\"style3\"><img src=/images/".$code['photo']." align=\"right\" class=\"right\">".nl2br($code['content'])."</p><br>\n";} $id = urlencode($id); //makes browser friendly //prev. page: **EDIT LINK PATH** $prev_page = $page - 1; if($prev_page >= 1) { echo("<b><<</b> <a href=/events/$prev_page><b>Prev.</b></a>"); } //Display middle pages: **EDIT LINK PATH** for($a = 1; $a <= $total_pages; $a++) { if($a == $page) { echo("<b> $a</b> | "); //no link } else { echo(" <a href=/events/$a> $a </a> | "); } } //next page: **EDIT THIS LINK PATH** $next_page = $page + 1; if($next_page <= $total_pages) { echo("<a href=/events/$next_page><b>Next</b></a> > >"); } //all done ?>[/code] Quote Link to comment Share on other sites More sharing options...
AdRock Posted November 1, 2006 Author Share Posted November 1, 2006 I have just edited this post in case anybody has idea of how to edit this script to display Google style paging Quote Link to comment Share on other sites More sharing options...
Psycho Posted November 1, 2006 Share Posted November 1, 2006 There's a pagination tutorial available right on this site: http://www.phpfreaks.com/tutorials/43/0.php Quote Link to comment Share on other sites More sharing options...
AdRock Posted November 1, 2006 Author Share Posted November 1, 2006 The script i have does the pagination but i only want to display a set number of links.When you have about 100 pages it looks rubbish when you have 100 page links. I want to display about 6 per page so it looks like << Prev 50 51 52 53 53 Next >> Quote Link to comment Share on other sites More sharing options...
Anidazen Posted November 1, 2006 Share Posted November 1, 2006 My guess would be all code will have a loop that goes through producing page links.Just change this from a loop that outputs all links, starting with $i or similar as 0 and going to the end, to starting at $i = $current -3; and going to $ii = $current + 3; if that makes any sense? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.