ricbax Posted November 16, 2006 Share Posted November 16, 2006 Does anyone know how I can modify the code below to go from [color=blue][u]<<[/u] [u]1[/u] [u]2[/u] [u]3[/u] [u]4[/u] [b]5[/b] [u]6[/u] [u]7[/u] [u]8[/u] [u]9[/u] [u]10[/u] [u]11[/u] [u]12[/u] [u]13[/u] [u]14[/u] [u]15[/u] [u]>>[/u][/color]to something more reduced[color=blue][u]<<[/u] [u]3[/u] [u]4[/u] [b]5[/b] [u]6[/u] [u]7[/u] [u]8[/u] [u]9[/u] [u]10[/u] [u]11[/u] [u]12[/u] [u]>>[/u][/color][code]<?phpclass Pager { function getPagerData($numHits, $limit, $page) { $numHits = (int) $numHits; $limit = max((int) $limit, 1); $page = (int) $page; $numPages = ceil($numHits / $limit); $page = max($page, 1); $page = min($page, $numPages); $offset = ($page - 1) * $limit; $ret = new stdClass; $ret->offset = $offset; $ret->limit = $limit; $ret->numPages = $numPages; $ret->page = $page; return $ret; } }?>[/code][code]<?php // get the pager input values $page = $_GET['page']; $limit = 15; $pgresult = mysql_query("select count(*) from my_db"); $total = mysql_result($pgresult, 0, 0); // work out the pager values $pager = Pager::getPagerData($total, $limit, $page); $offset = $pager->offset; $limit = $pager->limit; $page = $pager->page; echo "<span style='font-size: 10px;'>Result Pages: "; // output paging system (could also do it before we output the page content) if ($page == 1) // this is the first page - there is no previous page echo ""; else // not the first page, link to the previous page echo "<a href=\"results.php&page=" . ($page - 1) . "\">"." « "."</a>"; for ($i = 1; $i <= $pager->numPages; $i++) { echo ""; if ($i == $pager->page) echo "<span>$i</span>"; else echo "<a href=\"results.php?&page=$i\">$i</a>"; echo " | "; } if ($page == $pager->numPages) // this is the last page - there is no next page echo "" ; else // not the last page, link to the next page echo "<a href=\"results.php?&page=" . ($page + 1) . "\">"." » "."</a></span>";?>[/code] Link to comment https://forums.phpfreaks.com/topic/27507-paging-system-help/ Share on other sites More sharing options...
ricbax Posted November 17, 2006 Author Share Posted November 17, 2006 :DAfter plugging away at this for hours I finally came to a [b]rough [/b] solution. I feel that it really isn't a part of the Pager class, and would appreciate if someone could tell me how I could clean this up and make it a bit more cohesive with the class. Some discussion on this would be great before marking it * SOLVED *. However if I figure something out before the experts on here I will be sure to post my findings as I did here already.My solution:[code=PHP SOLUTION]<?php // get the pager input values $page = $_GET['page']; $limit = 15; if(empty($start))$start=0; $result = mysql_query("select count(*) from my_db where mix_id='".$_GET['id']."'"); $total = mysql_result($result, 0, 0); $per_page = 15; // Number of items to show per page (MUST MATCH $limit, so if $limit = 1, $per_page = 1) $showeachside = 20; // Number of items to show either side of selected page $cur = ceil($start / $per_page)+1; // Current page number $thispage = $PHP_SELF; // work out the pager values $pager = Pager::getPagerData($total, $limit, $page); $offset = $pager->offset; $limit = $pager->limit; $page = $pager->page; ?><?php$pg=1;if(($start-$per_page) >= 0){ $next = $start-$per_page;?><a href="<?php print("$thispage".($next>0?("?id=".$_GET['id']."&div=open&page=".($cur - 1)."&start=").$next:"?id=".$_GET['id']."&div=open&page=".($cur - 1)."&start="));?>">«</a> <?php}?><?php$eitherside = ($showeachside * $per_page);for($y=0;$y<$total;$y+=$per_page){ $class=($y==$start)?"pageselected":""; if(($y > ($start - $eitherside)) && ($y < ($start + $eitherside))) {?> <a class="<?php print($class);?>" href="<?php print("$thispage".($y>0?("?id=".$_GET['id']."&div=open&page=".($pg)."&start=").$y:"?id=".$_GET['id']."&div=open&page=".($pg)."&start="));?>"><?php print($pg);?></a> <?php } $pg++;}?><?phpif($start+$per_page<$total){?> <a href="<?php print("$thispage?id=".$_GET['id']."&div=open&page=".($cur + 1)."&start=".max(0,$start+$per_page));?>">»</a></span><?php}?>[/code] Link to comment https://forums.phpfreaks.com/topic/27507-paging-system-help/#findComment-126256 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.