> I have successfully implemted "pagenting" on one of my pages to generate " > PREV 1,2,3,4 (etc) NEXT" depending on the records that are being returned > and the number of rows i specify in a LIMIT. > > One little problem, right now I have very few records so I dont mind it > giving a 1,2,3,4 etc till 10 or more but soon I will have quite a lot of > records and I dont want the client to see a whole page of 1,2,3,4.... for > him to click, is there anyway I can cut it down (eg. like google) to show > only 10 pages or such?? > > Below is the code that I am using and which so far is working perfectly: > > <?php > $connected=mysql_connect("localhost","estwe_uma","balh") or die > ('connect:'.mysql_error()); > mysql_select_db ("estwe_bh"); > > $limit = 10; > > $query_count = "SELECT COUNT(*) FROM web_shared"; > $result_count = mysql_query($query_count) or die("Error: " . > mysql_error()); > $totalrows = mysql_result($result_count,0); > > $page = $_GET['page']; > > if(empty($page)) > $page = 1; > > $limitvalue = $page * $limit - ($limit); > > $database["sql"] = "select * from webplans_shared order by company,price > LIMIT $limitvalue, $limit"; > > print("html output comes here"); > > if(mysql_num_rows($result) == 0) > { echo(" Sorry, No matches found!"); exit;} > > > if($page != 1){ > $pageprev = $page-1; > > echo("<a > href=\"search.template.php?page=$pageprev\">PREV</a> > "); > }else > echo("PREV "); > > $numofpages = $totalrows / $limit; > > for($i = 1; $i <= $numofpages; $i++){ > if($i == $page) > echo($i.": "); > else > echo("<a href=\"search.template.php?page=$i\">$i</a> "); > }
Instead of going from 1 until $numofpages, go from $page-5 to $page+5, for example... $minpage = max(1,$page-5); $maxpage = min($numofpages,$page+5); for($i = $minpage; $i <= $maxpage; $i++) { ... } ---John W. Holmes... Amazon Wishlist: http://www.amazon.com/o/registry/3BEXC84AB3A5E PHP Architect - A monthly magazine for PHP Professionals. Get your copy today. http://www.phparch.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php