pagenting logic to cut short

From: Date: Tue, 03 Jun 2003 17:12:11 +0000
Subject: pagenting logic to cut short
Groups: php.general 
Request: Send a blank email to php-general+get-149996@lists.php.net to get a copy of this message
Hi guys, 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>&nbsp; &nbsp; &nbsp;"); }else echo("PREV&nbsp;&nbsp;&nbsp;"); $numofpages = $totalrows / $limit; for($i = 1; $i <= $numofpages; $i++){ if($i == $page) echo($i.":&nbsp;"); else echo("<a href=\"search.template.php?page=$i\">$i</a>&nbsp;"); } if(($totalrows % $limit) != 0){ if($i == $page) echo($i.":&nbsp;"); else echo("<a href=\"search.template.php?page=$i\">$i</a>&nbsp;"); if(($totalrows - ($limit * $page)) > 0){ $pagenext = $page+1; echo("&nbsp;&nbsp; <a href=\"search.template.php?page=$pagenext\">NEXT </a>"); }else echo(".."); } thanks in advance, Cheers, -Ryan

« previous php.general (#149996) next »