How to use large pagination in a limited area

Reply

Join Date: Jun 2008
Posts: 64
Reputation: vijaysoft1 is an unknown quantity at this point 
Solved Threads: 0
vijaysoft1's Avatar
vijaysoft1 vijaysoft1 is offline Offline
Junior Poster in Training

How to use large pagination in a limited area

 
0
  #1
Sep 8th, 2009
How to use large pagination in a limited area , plz see the bottom pictures , please help me ........
as an example in my page , i have more than 100 posts

no my pagination system is like this
1 2 3 4 5 6 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24

but i want to do like this , so please help me

1 2 3 4 5 6 8 9 10 11 22 23 24

non limited - http://i31.tinypic.com/ztsmf7.jpg
limited - http://i31.tinypic.com/28wp7ys.jpg
please help me ...........
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 954
Reputation: ardav will become famous soon enough ardav will become famous soon enough 
Solved Threads: 126
ardav's Avatar
ardav ardav is offline Offline
Posting Shark

Re: How to use large pagination in a limited area

 
0
  #2
Sep 8th, 2009
Just use your while loop to find the number of pages (as usual), then use some rules to display certain pages.

Do you want to display a maximum of 14 pages as suggested in your post? If so do you want the last 4 pages to link to the last pages?

1) If the total number of pages = 14 or less, display all page links.

2) Otherwise display the pages if the number is 10 or less OR display if the page number is greater than the total number of pages - 4.

I'm sure there are other formulae you could use.
"...the woods would be a very silent place if no birds sang except for the best"
All opinions count.
F'enw i yw Mr. Blaidd. Byddwch yn ofalus - dwi'n cnoi.
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 1,449
Reputation: cwarn23 has a spectacular aura about cwarn23 has a spectacular aura about cwarn23 has a spectacular aura about 
Solved Threads: 135
cwarn23's Avatar
cwarn23 cwarn23 is offline Offline
Nearly a Posting Virtuoso

Re: How to use large pagination in a limited area

 
0
  #3
Sep 9th, 2009
Try the following code:
  1. <style type="text/css">
  2. A:link {font-weight:bold; font-family:"Arial";}
  3. A:visited {font-weight:bold; font-family:"Arial";}
  4. A:active {font-weight:bold; font-family:"Arial";}
  5. A:hover {font-weight:bold; font-family:"Arial";}
  6. </style>
  7. <?
  8. $number_of_pages=100; //maximum number of pages
  9. $current_page=50; //set the current page probably with $_GET
  10. for ($i=1;$i<=$number_of_pages;$i++) {
  11. if ($i<11) {
  12. echo ($i>1)? ' - ':''; // add dash between numbers.
  13. echo '<a href="index.php?id='.$i.'">'.$i.'</a>';
  14. }
  15. if (($i>=($current_page-1) && $i<=($current_page+1)) || $i>=($number_of_pages-2)) {
  16. echo ' - <a href="index.php?id='.$i.'">'.$i.'</a>';
  17. }
  18. }
  19. ?>
Try not to bump 10 year old threads as it can be really annoying.
Like php then read my website at http://syntax.cwarn23.net/
Star-Trek-Atlantis - now that's what I call a movie ^_^
My favourite PC. - MacGyver Fan
Bad english note: dis-iz-2b4u
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 64
Reputation: vijaysoft1 is an unknown quantity at this point 
Solved Threads: 0
vijaysoft1's Avatar
vijaysoft1 vijaysoft1 is offline Offline
Junior Poster in Training

Re: How to use large pagination in a limited area

 
0
  #4
Sep 13th, 2009
  1. for($i = 1; $i <= $total_newspage; $i++)
  2. {
  3. if(($newspage) == $i)
  4. {
  5. echo "$i\n ";
  6. }
  7. else
  8. {
  9. echo "<a href=\"news.php?newspage=$i\">$i</a>\n ";
  10. }
  11. }

i am using this lines of code to generate my basic pagination , how to modify it to my needs . please .............
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 1,449
Reputation: cwarn23 has a spectacular aura about cwarn23 has a spectacular aura about cwarn23 has a spectacular aura about 
Solved Threads: 135
cwarn23's Avatar
cwarn23 cwarn23 is offline Offline
Nearly a Posting Virtuoso

Re: How to use large pagination in a limited area

 
0
  #5
Sep 13th, 2009
Originally Posted by vijaysoft1 View Post
  1. for($i = 1; $i <= $total_newspage; $i++)
  2. {
  3. if(($newspage) == $i)
  4. {
  5. echo "$i\n ";
  6. }
  7. else
  8. {
  9. echo "<a href=\"news.php?newspage=$i\">$i</a>\n ";
  10. }
  11. }

i am using this lines of code to generate my basic pagination , how to modify it to my needs . please .............
Why dont you explain the syntax you want when the middle page of 100 pages is selected. Example:
Page 50 selected - 100 pages total
.1  2  3  4  5  48  49  50  51  52  98  99  100
If you could show me a codebox like the above but your version of what the pegination should look like then I shall create it.
Try not to bump 10 year old threads as it can be really annoying.
Like php then read my website at http://syntax.cwarn23.net/
Star-Trek-Atlantis - now that's what I call a movie ^_^
My favourite PC. - MacGyver Fan
Bad english note: dis-iz-2b4u
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 64
Reputation: vijaysoft1 is an unknown quantity at this point 
Solved Threads: 0
vijaysoft1's Avatar
vijaysoft1 vijaysoft1 is offline Offline
Junior Poster in Training

Re: How to use large pagination in a limited area

 
0
  #6
Sep 13th, 2009
this is the full code i am using and it working perfect . what i want to do is , i have more than 100 pages ( '$total_newspage' ) but i want to display like this

1 2 3 4 5 6 7 8 9 10 ... 100 ALL

when i click on 10 , want to show like this

10 11 12 13 14 15 16 17 18 19 ... 100 ALL

and after 19

19 20 21 22 23 24 25 26 27 28 ... 100 ALL , and so on

now u got it what i want to do , plz help me


  1. <?php
  2.  
  3.  
  4. if(!isset($_GET['newspage'])){
  5. $newspage = 1;
  6. } else {
  7. $newspage = $_GET['newspage'];
  8. }
  9.  
  10.  
  11. // Define the number of results per page
  12. $max_results = 2;
  13.  
  14. // Figure out the limit for the query based
  15. $from = (($newspage * $max_results) - $max_results);
  16.  
  17. $query_Record_data = "SELECT txtPostTitle, txtPostDate, txtPostContent, txtUsername FROM generic ORDER BY intPostID ASC LIMIT $from, $max_results";
  18. $Record_data = mysql_query($query_Record_data, $mysql_Connection) or die(mysql_error());
  19. $row_Record_data = mysql_fetch_assoc($Record_data);
  20. $totalRows_Record_data = mysql_num_rows($Record_data);
  21.  
  22. // Figure out the total number of results in DB:
  23. $total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM generic"),0);
  24.  
  25. // Figure out the total number of pages. Always round up using ceil()
  26. $total_newspage = ceil($total_results / $max_results);
  27.  
  28. echo "<p style=\"clear:both;\" align=\"center\">\n";
  29. echo $total_newspage;
  30.  
  31. ?>


  1. <?php
  2.  
  3. //------------------ previous link----------------------
  4. if($newspage > 1)
  5. {
  6. $prev = ($newspage - 1);
  7. echo "<a href=\"apps.php?newspage=$prev\">‹‹ Previous</a>\n ";
  8. echo $i;
  9. }
  10.  
  11. //----------Displaying pagination bar---------------
  12.  
  13. for($i = 1; $i <= $total_newspage ; $i++)
  14. {
  15. if(($newspage) == $i)
  16. {
  17. echo "$i\n ";
  18. }
  19. else
  20. {
  21. echo "<a href=\"apps.php?newspage=$i\">$i</a>\n ";
  22. }
  23. }
  24.  
  25. //-------------- Build Next Link ------------------------------------------
  26.  
  27. if($newspage < $total_newspage)
  28. {
  29. $next = ($newspage + 1);
  30.  
  31. echo "<a href=\"apps.php?newspage=$next\">Next ››</a>\n";
  32. }
  33. echo "</p>\n";
  34.  
  35. ?>

now u got it what i am trying to do , plz help me
Last edited by vijaysoft1; Sep 13th, 2009 at 12:33 pm.
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 1,449
Reputation: cwarn23 has a spectacular aura about cwarn23 has a spectacular aura about cwarn23 has a spectacular aura about 
Solved Threads: 135
cwarn23's Avatar
cwarn23 cwarn23 is offline Offline
Nearly a Posting Virtuoso

Re: How to use large pagination in a limited area

 
0
  #7
Sep 15th, 2009
Try the following:
  1. <?
  2. $number_of_pages=100; //maximum number of pages
  3. $current_page=$_GET['newspage']; //set the current page
  4.  
  5. //set above variables
  6. //don't change the below
  7. $tmp=$current_page+10;
  8. for ($i=1;$i<=$number_of_pages;$i++) {
  9. if (($i>=($current_page-1) && $i<($tmp)) || $i==$number_of_pages) {
  10. echo '<a href="index.php?newspage='.$i.'">'.$i.'</a>';
  11. echo (($i<($tmp) && ($tmp)<=$number_of_pages) || ($i<($tmp) && $currentpage<$number_of_pages))? ' - ':''; // add dash between numbers.
  12. }
  13. }
  14. ?>
Last edited by cwarn23; Sep 15th, 2009 at 2:42 am. Reason: error
Try not to bump 10 year old threads as it can be really annoying.
Like php then read my website at http://syntax.cwarn23.net/
Star-Trek-Atlantis - now that's what I call a movie ^_^
My favourite PC. - MacGyver Fan
Bad english note: dis-iz-2b4u
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 72
Reputation: smartness is an unknown quantity at this point 
Solved Threads: 10
smartness's Avatar
smartness smartness is offline Offline
Junior Poster in Training

Re: How to use large pagination in a limited area

 
0
  #8
Sep 15th, 2009
I use this function to paginate:

  1. <?php
  2. if(isset($_GET["page"])) {
  3. $page = $_GET["page"];
  4. } else {
  5. $page = 1;
  6. }
  7. $totalPages = 1000;
  8. function paging($page, $totalPages) {
  9. $printPages = 7; //Show only X pages
  10. $i = 1;
  11. $previous_page = ($page > 1) ? $page - 1 : 1;
  12. $next_page = $page + 1;
  13. if($totalPages < $printPages) {
  14. $printPages = $totalPages;
  15. }
  16. echo '<div class="pagination" align="center">
  17. <ul>';
  18. if($page > 1) {
  19. echo ' <li><a href="?page=1">&laquo;&laquo; First</a></li> ';
  20. echo ' <li><a href="?page='.$previous_page.'">&laquo; Prev</a></li> ';
  21. if($totalPages > 0) {
  22. //Nothing for now, used to have a | separator here
  23. }
  24. }
  25.  
  26. if($page - 3 <= 0)
  27. {
  28. $currentPage = 1;
  29. }
  30. elseif($page > 3 && $page + 3 < $totalPages)
  31. {
  32. $currentPage = $page - 3;
  33. }
  34. else
  35. {
  36. $currentPage = $totalPages - ($printPages - 1);
  37. }
  38.  
  39. while($i <= $printPages)
  40. {
  41. echo '<li><a';
  42. if($page == $currentPage) {
  43. echo ' class="currentpage" ';
  44. }
  45. echo ' href="?page='.$currentPage.'"> '.$currentPage.' </a></li>&nbsp;';
  46. $currentPage++;
  47. $i++;
  48. }
  49.  
  50. if($page < $totalPages)
  51. {
  52. $next = $page + 1;
  53. echo '&nbsp;<li><a href="?page='.$next.'">Next &raquo;</a></li> ';
  54. echo ' <li> <a href="?page='.$totalPages.'">Last &raquo;&raquo;</a></li> ';
  55.  
  56. }
  57. echo '</ul></div>';
  58. }
  59.  
  60. //Use it
  61. paging($page, $totalPages)
  62. ?>

EDITED Now its better!


You can mod. it for you...

p.s. This is used for styling:
http://www.dynamicdrive.com/style/cs...nation_links/#
Last edited by smartness; Sep 15th, 2009 at 8:02 am.
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 64
Reputation: vijaysoft1 is an unknown quantity at this point 
Solved Threads: 0
vijaysoft1's Avatar
vijaysoft1 vijaysoft1 is offline Offline
Junior Poster in Training

Re: How to use large pagination in a limited area

 
0
  #9
Sep 17th, 2009
hi friend thanks for u r help and this code , it is working perfect

but i am confused while implementing , my idea , following

this is my pagination bar
---------------------------
1 2 3 4 5 6 7 8 9 .. 98 99 100


when i click on 9th page [ here my $printPages = 9 ] , i want to increment $page ( $page = $page+9) , means i want to display like this

9 10 11 12 13 14 15 16 17 ... 98 99 100

17 18 19 20 21 22 23 24 25 .. 98 99 100
and so on

please help me , i am very confused , so plz help me
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 64
Reputation: vijaysoft1 is an unknown quantity at this point 
Solved Threads: 0
vijaysoft1's Avatar
vijaysoft1 vijaysoft1 is offline Offline
Junior Poster in Training

Re: How to use large pagination in a limited area

 
0
  #10
Sep 18th, 2009
plz anybody help me.................
Reply With Quote Quick reply to this message  
Reply

Message:



Similar Threads
Other Threads in the PHP Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC