kfir91 Posted May 15, 2009 Share Posted May 15, 2009 i draw the database data to my page and i orders that data in pages with LIMIT $start and $max ... this is my for : for($i=1; $i <= $pages+1; $i++) { if ($i == "".($page+1)."") $tp .= "<span class=\"current\">{$i}</span>"; else $tp .= "<a href=\"?act=$thepage&page=".($i-1)."\">{$i}</a>"; } the for give me list of all the pages that he order. so now i need way that i order the page more. to example i have 7 pages if i inside 5 page i want that this see pages: 3,4,5,6,7,8 i want two pages before the page and three pages after the page. if i in 2 page i will see : 1,2,3,4,5,6 if i in 1 page i will see : 1,2,3,4,5,6 if i in 6 page i will see : 2,3,4,5,6,7 ... if u have another order pls say me ... tnx Quote Link to comment https://forums.phpfreaks.com/topic/158250-i-need-help-with-pages-orders/ Share on other sites More sharing options...
GingerRobot Posted May 15, 2009 Share Posted May 15, 2009 I think i'd go with something like this: <?php $currPage = 6;//the page you're on $pagesToShow = 5;//the number of pages to show $pages = array($currPage);//an array of the pages we'll show $previousPages = 0;//the number of pages we've added that are before the current one $maxPages = 10;//the maximum number of pages available //Add up to 2 pages before the current one while($previousPages <2 ){ if($currPage-1 > 0){ array_unshift($pages,--$currPage); $previousPages++; $pagesToShow++; }else{ break; } } //add the rest of the pages after, if they exist while($pagesToShow > ){ if($currPage+1 <= $maxPages){ array_push($pages,++$currPage); $pagesToShow++; }else{ break; } } //output the pages foreach($pages as $page){ echo $page.' '; } ?> Untested, but you should get the general idea. Quote Link to comment https://forums.phpfreaks.com/topic/158250-i-need-help-with-pages-orders/#findComment-834669 Share on other sites More sharing options...
kfir91 Posted May 15, 2009 Author Share Posted May 15, 2009 tnx its good tnx tnx tnx =] Quote Link to comment https://forums.phpfreaks.com/topic/158250-i-need-help-with-pages-orders/#findComment-834689 Share on other sites More sharing options...
kfir91 Posted May 15, 2009 Author Share Posted May 15, 2009 dude if i in 2 page and i have 2 page its not see me 1,2 ... its see only 2 why ? Quote Link to comment https://forums.phpfreaks.com/topic/158250-i-need-help-with-pages-orders/#findComment-834708 Share on other sites More sharing options...
.josh Posted May 15, 2009 Share Posted May 15, 2009 it looks like from your code $page is what the current page is, and $pages is what your total page count is. Your loop is: for($i=1; $i <= $pages+1; $i++) { So instead of counting from 1 to $pages, you would count from ($page - $x) to ($page + $x) where $x is how many pages on each side of the current page you want. You will also want to add a condition inside the loop to make sure the current iteration ($i) is > 1 and < $pages before you echo something. Quote Link to comment https://forums.phpfreaks.com/topic/158250-i-need-help-with-pages-orders/#findComment-834715 Share on other sites More sharing options...
kfir91 Posted May 15, 2009 Author Share Posted May 15, 2009 it looks like from your code $page is what the current page is, and $pages is what your total page count is. Your loop is: for($i=1; $i <= $pages+1; $i++) { So instead of counting from 1 to $pages, you would count from ($page - $x) to ($page + $x) where $x is how many pages on each side of the current page you want. You will also want to add a condition inside the loop to make sure the current iteration ($i) is > 1 and < $pages before you echo something. and if the condition not ok ? what the else Quote Link to comment https://forums.phpfreaks.com/topic/158250-i-need-help-with-pages-orders/#findComment-834723 Share on other sites More sharing options...
.josh Posted May 15, 2009 Share Posted May 15, 2009 if the $i is less than 0 or greater than $pages, don't echo. The end. Quote Link to comment https://forums.phpfreaks.com/topic/158250-i-need-help-with-pages-orders/#findComment-834724 Share on other sites More sharing options...
kfir91 Posted May 15, 2009 Author Share Posted May 15, 2009 if the $i is less than 0 or greater than $pages, don't echo. The end. tnx dude its wonderful tnx =] Quote Link to comment https://forums.phpfreaks.com/topic/158250-i-need-help-with-pages-orders/#findComment-834738 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.