davieboy Posted April 13, 2007 Share Posted April 13, 2007 Hi all Im using the pagination successfully, but now i do have quite alot of pages being given in results eg PREV15 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 NEXT15 im using the standard <?php include("config.php"); mysql_connect($db_host,$db_user,$db_pass); mysql_select_db ($db_name) or die (mysql_error()); $limit = 15; $query_count = "SELECT * FROM photos WHERE status = 'accepted'"; $result_count = mysql_query($query_count); $totalrows = mysql_num_rows($result_count); $PHP_SELF = $_SERVER['PHP_SELF']; if(!isset($_GET['page'])){ // Checks if the $page variable is empty (not set) $page = 1; // If it is empty, we're on page 1 } else{ $page = $_GET['page']; } $limitvalue = $page * $limit - ($limit); // Ex: (page2 * 5(items per page) = 10) - 5 = 5 <- data starts at 5 and after my content if($page != 1){ $pageprev = $page - 1; //decrementing $page-- does not work on all php configurations. echo("<a href=\"$PHP_SELF?page=$pageprev\"><b>PREV</b>".$limit."</a> "); }else{ echo("PREV".$limit." "); } $numofpages = $totalrows / $limit; #echo "<br>", $totalrows; #exit; for($i = 1; $i <= $numofpages; $i++){ /* This for loop will add 1 to $i at the end of each pass until $i is greater than $numofpages. */ if($i == $page){ echo($i." "); }else{ echo("<a href=\"$PHP_SELF?page=$i\">$i</a> "); } } //code above has been decoded lozza if(($totalrows % $limit) != 0){ if($i == $page){ echo($i." "); }else{ echo("<a href=\"$PHP_SELF?page=$i\">$i</a> "); } } if(($totalrows - ($limit * $page)) > 0){ $pagenext = $page + 1; //incrementin $page like $page++ does not work in all enviroments echo("<a href=\"$PHP_SELF?page=$pagenext\"><b>NEXT</b>".$limit."</a>"); }else{ echo("NEXT".$limit); } mysql_free_result($result); ?> Just wondering how i can limit the results to say 10->15 pages and have the next and previous links on the end eg instead of the above have PREV15 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 NEXT15 Thanks to all David Quote Link to comment Share on other sites More sharing options...
PC Nerd Posted April 13, 2007 Share Posted April 13, 2007 um, roughly youd simply find the variable holding the values for the pagination, and simply go if(< 5 || > 15) {echo "next";} just format and add the values as set gdlk Quote Link to comment Share on other sites More sharing options...
davieboy Posted June 7, 2007 Author Share Posted June 7, 2007 i cant see how to get this done. when editing pages it makes no difference. could someone help me with it? david 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.