Rita_Ruah Posted May 27, 2013 Share Posted May 27, 2013 Hello, I have manually created a simple pagination function, but unfortunately, I am having trouble when it comes to limit the number of pages shown... At the present, If there are 10 pages, I show all the pages, but my goal was to only show 5 pages... Example:If I am on page 1 I only see:[1] 2 3 4 5 If I am on two: [2] 3 4 5 6 If I am on three: [3] 4 5 6 7 What should I do? this is my current cycle: if($number_pages > $num_pages_list /*5 in this case*/) { for($i=1; $i <= $number_pages; $i++) { if($i == $_GET['page']) { echo '<a href="'.$page.'?page='.$i.'&i='.($results_page*$i-$results_page).'"><b>'.$i.'</b></a>'; }else{ echo '<a href="'.$page.'?page='.$i.'&i='.($results_page*$i-$results_page).'">'.$i.'</a>'; } } } In this example I still show every page... Link to comment https://forums.phpfreaks.com/topic/278439-php-pagination-adjacent/ Share on other sites More sharing options...
Jessica Posted May 27, 2013 Share Posted May 27, 2013 for($i=1; $i <= $number_pages; $i++)Fix that line. If you know what it does, it should be fairly easy to change it to what you've just said you want it to do. Link to comment https://forums.phpfreaks.com/topic/278439-php-pagination-adjacent/#findComment-1432554 Share on other sites More sharing options...
Rita_Ruah Posted May 27, 2013 Author Share Posted May 27, 2013 for($i=1; $i <= $number_pages; $i++)Fix that line. If you know what it does, it should be fairly easy to change it to what you've just said you want it to do. Hi there, I know what it does, for i equals 1, while i is lower or equals number_pages, etc etc... But I am not sure what to do here, can you give me a hint? Please, I am stuck here for hours... Thanks! Link to comment https://forums.phpfreaks.com/topic/278439-php-pagination-adjacent/#findComment-1432599 Share on other sites More sharing options...
Rita_Ruah Posted May 27, 2013 Author Share Posted May 27, 2013 for($i = $_GET['page']; $i <= $number_pages; $i++) { //Maybe this? //Please help or explain the logic of what to do, the rest i will be capable to do. //Sorry } Link to comment https://forums.phpfreaks.com/topic/278439-php-pagination-adjacent/#findComment-1432600 Share on other sites More sharing options...
Jessica Posted May 27, 2013 Share Posted May 27, 2013 Well, your complaint is that it's printing all the numbers up to $number_pages. You want it to print up to $num_pages_list. You also are starting at 1 right now. You say you want to start at the current page. There are two things to change. Link to comment https://forums.phpfreaks.com/topic/278439-php-pagination-adjacent/#findComment-1432602 Share on other sites More sharing options...
Rita_Ruah Posted May 27, 2013 Author Share Posted May 27, 2013 Well, your complaint is that it's printing all the numbers up to $number_pages. You want it to print up to $num_pages_list. You also are starting at 1 right now. You say you want to start at the current page. There are two things to change. Oh sorry, my bad, ok, I'm going to try to explain again: Currently, my pagination works fine (next - previous - first page - last page), but the problem is that I need to only show 5 numbers (five pages at once, and currently I am showing every page). What I want is showing every page buuuuut make sure that there are only 5 pages at once, thus the example (imagine that there is a total of 7 pages in the pagination: If I am at page 1 I will see: [1] 2 3 4 5 If I am at page 2 I will see: [2] 3 4 5 6 If I am at page 3: [3] 4 5 6 7 If I am at page 4: 3 [4] 5 6 7 Did you understand? (Sorry I am italian) Link to comment https://forums.phpfreaks.com/topic/278439-php-pagination-adjacent/#findComment-1432604 Share on other sites More sharing options...
Jessica Posted May 27, 2013 Share Posted May 27, 2013 Yes, I understand. I told you what your code is doing now. Change those parts to do what you want. Link to comment https://forums.phpfreaks.com/topic/278439-php-pagination-adjacent/#findComment-1432605 Share on other sites More sharing options...
Rita_Ruah Posted May 27, 2013 Author Share Posted May 27, 2013 Yes, I understand. I told you what your code is doing now. Change those parts to do what you want. The first part I think that it's assigning the current page for $i, right? Next I have no idea... Please help... I feel dizzy, pagiantion was fine and was my favorite project until this problem I only ask because I am desperate... Link to comment https://forums.phpfreaks.com/topic/278439-php-pagination-adjacent/#findComment-1432607 Share on other sites More sharing options...
Jessica Posted May 27, 2013 Share Posted May 27, 2013 You can't be that desperate, you didn't even try to change it. Link to comment https://forums.phpfreaks.com/topic/278439-php-pagination-adjacent/#findComment-1432610 Share on other sites More sharing options...
Rita_Ruah Posted May 27, 2013 Author Share Posted May 27, 2013 You can't be that desperate, you didn't even try to change it. But I am on my tablet, is there any php editor/run for tablet (android)? Only tomorrow I will be able to try to fix it... please Jessica, if you don't want to give the answer, atleast try to explain to me what to do... I am thinking about: for($i = $_GET['page']; $i <= $num_pages_list+$_GET['page'];i++) { if($i <= $num_pages) { echo $i; } } EDIT: This won't work because the pages aren't limited to 5 right? Damn... Link to comment https://forums.phpfreaks.com/topic/278439-php-pagination-adjacent/#findComment-1432612 Share on other sites More sharing options...
Jessica Posted May 27, 2013 Share Posted May 27, 2013 Viewing page: 1 of 10 [ *1* 2 3 4 5 ] Viewing page: 2 of 10 [ *2* 3 4 5 6 ] Viewing page: 3 of 10 [ *3* 4 5 6 7 ] Viewing page: 4 of 10 [ *4* 5 6 7 8 ] Viewing page: 5 of 10 [ *5* 6 7 8 9 ] Viewing page: 6 of 10 [ *6* 7 8 9 10 ] Viewing page: 7 of 10 [ 6 *7* 8 9 10 ] Viewing page: 8 of 10 [ 6 7 *8* 9 10 ] Viewing page: 9 of 10 [ 6 7 8 *9* 10 ] Viewing page: 10 of 10 [ 6 7 8 9 *10* ] <?php $display_pages = 5; $total_pages = 10; for($i=1; $i<=10; $i++){ $current_page = $i; echo "Viewing page: {$current_page} of {$total_pages}\n"; echo '['; $start = $current_page; if($total_pages-$start < $display_pages){ $start = ($total_pages-$display_pages)+1; } for($k=$start; $k<($start+$display_pages); $k++){ if($k==$current_page){ echo " *{$k}* "; }else{ echo " {$k} "; } } echo ']'; echo "\n\n"; } Link to comment https://forums.phpfreaks.com/topic/278439-php-pagination-adjacent/#findComment-1432615 Share on other sites More sharing options...
Rita_Ruah Posted May 27, 2013 Author Share Posted May 27, 2013 <?php $display_pages = 5; $total_pages = 10; for($i=1; $i<=10; $i++){ $current_page = $i; echo "Viewing page: {$current_page} of {$total_pages}\n"; echo '['; $start = $current_page; if($total_pages-$start < $display_pages){ $start = ($total_pages-$display_pages)+1; } for($k=$start; $k<($start+$display_pages); $k++){ if($k==$current_page){ echo " *{$k}* "; }else{ echo " {$k} "; } } echo ']'; echo "\n\n"; } This looks good thanks Whenever I finish the function to paginate (it's a pagination without database), I will tell if it worked! Thank you Jessica! Link to comment https://forums.phpfreaks.com/topic/278439-php-pagination-adjacent/#findComment-1432618 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.