dr_ghost Posted May 16, 2009 Share Posted May 16, 2009 plz anyone help me in making this counter good the original one i'm using is like that and the one i want to be modified like that and the original code used is that <? echo"<div class='pagi'>"; for($i=1;$i<=$pages;$i++) { if($page==$i) echo"<span class='current'> $i& nbsp;</span>"; else { echo " "; echo"<a class='paginate' href='index.php?page=$i'> $i </a>"; } } if($page>1) { $prev=$page-1; echo " "; echo"<a class='paginate' href='index.php?page=$pre v'> « Prev </a>"; } if($page<$pages) { $next=$page+1; echo" "; echo"<a class='paginate' href='index.php?page=$nex t'> Next » </a>"; } echo"</div>"; ?> plz any one give me the modified code to be like modified image Quote Link to comment https://forums.phpfreaks.com/topic/158392-problem-with-page-counter/ Share on other sites More sharing options...
gregor171 Posted May 16, 2009 Share Posted May 16, 2009 Lol! You want right to left pager. Something like this should work: $show_pages=20; // this will show max 20 buttons $current_page = isset($_GET['page']) ? (int) $_GET['page'] : 1; // safely read current page if($pages<$show_pages){ // if we have only a few pages $show_pages=$pages; } // get the fist page $start_from = 1; $show_to_first=false; if($current_page>$show_pages){ $show_to_first=true; $start_from=$current_page-($show_pages/2); } $to_last_page_html=""; $to_first_page_html=""; if($show_to_first){ // here you populate $to_first_page_html with html of ... and button to first page } if(($start_from+$show_pages)<$pages){ // here you populate $to_last_page_html with html of last page button and ... }else if(($start_from+$show_pages)>=$pages){ $show_pages = ($show_pages/2)+$pages - $current_page; } // rearrange for sentence for left to right pager echo $to_last_page_html; for($i=($start_from+$show_pages);$i>=$start_from;$i--){ // your pager code here } echo $to_first_page_html; Quote Link to comment https://forums.phpfreaks.com/topic/158392-problem-with-page-counter/#findComment-835475 Share on other sites More sharing options...
dr_ghost Posted May 17, 2009 Author Share Posted May 17, 2009 I want to modify the code i put not making a new code Quote Link to comment https://forums.phpfreaks.com/topic/158392-problem-with-page-counter/#findComment-835737 Share on other sites More sharing options...
GingerRobot Posted May 17, 2009 Share Posted May 17, 2009 I want to modify the code i put not making a new code Err..but your code does the wrong thing. In some cases, it's easier to start from scratch. Quote Link to comment https://forums.phpfreaks.com/topic/158392-problem-with-page-counter/#findComment-835745 Share on other sites More sharing options...
Daniel0 Posted May 17, 2009 Share Posted May 17, 2009 I want to modify the code i put not making a new code That presupposes your method/code is good. Perhaps you should read the "how to ask questions" HOWTO linked to in my signature. Quote Link to comment https://forums.phpfreaks.com/topic/158392-problem-with-page-counter/#findComment-835746 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.