Register Members List Search Today's Posts Mark Forums Read

Reply
 
Article Options
[How-To] Paginate your results
Revan
Join Date: Jan 2004
Posts: 1,671

Started doing my first if...else chain in 2004, and released my first major vBulletin modification in August 2004 with the first version of the RPG Integration Hack.

Norway
by Revan Revan is offline 07 Jul 2006
Rating: (1 vote - 5.00 average)

Don't you just hate it...? You have hundreds, no maybe even thousands of records being returned from a query, and the page lags for seconds at a time as well as the page being longer than a giraffe's neck.
Wouldn't it be neat to seperate them into pages? Just like vBulletin does? Of course it would.

This guide assumes you are familiar enough with vBulletin and PHP in general, so I won't go into great detail about what each bit does.
This is intended for hack authors.

So, without further ado, I give you (drumroll please) [How-To] Paginate your results!
  1. Your PHP code
    1. The first thing you need to do is clean the two variables that tells you what page you are on and how many records to clean per page.
      Add this code:

      Block Disabled:      (Update License Status)  
      Suspended or Unlicensed Members Cannot View Code.

    2. Then, you have to count all the entries that exists in the table you wish to display results from. Like so:

      Block Disabled:      (Update License Status)  
      Suspended or Unlicensed Members Cannot View Code.

    3. Next up, you'll want to call a fancy vB function that'll make sure all these variables play nice together.

      Block Disabled:      (Update License Status)  
      Suspended or Unlicensed Members Cannot View Code.

      The last two arguments, in this example 100 and 25, are the Max Per Page and Default Per Page.
      You may want to swap them with vBOptions settings you write, or you can choose your own values.
    4. Next up, we are going to prepare your variables for the SQL query. This we do by using this code I blatantly copied from a random vB file:

      Block Disabled:      (Update License Status)  
      Suspended or Unlicensed Members Cannot View Code.

      The only bit you have to replace here is the $bannecount['bannedcount'] which is the variable we fetched in the count query above.
    5. Then we have the actual query. An example is this:

      Block Disabled:      (Update License Status)  
      Suspended or Unlicensed Members Cannot View Code.

      The only bit about the query you need to blatantly steal is the LIMIT clause. That's what's ensuring the pages are splitted like you want them to be. I just copied it all because I wanted to.
    6. The comment above this bit of code makes it self-explanatory:

      Block Disabled:      (Update License Status)  
      Suspended or Unlicensed Members Cannot View Code.

      Obviously you will want to replace the filename and do= section as well as the $bannedcount variable.
  2. Your template code
    Put this code above and below your content table to generate a pagenav on top and bottom:

    Block Disabled:      (Update License Status)  
    Suspended or Unlicensed Members Cannot View Code.


And you're done
If everything works correctly you should now have a fully vBised page navigation.
Views: 6705
Reply With Quote
Comments
  #2  
Old 15 Jul 2006, 05:29
Antivirus's Avatar
Antivirus Antivirus is offline
 
Join Date: Sep 2004
Phillip... you are my hero, i needed this, thanks!

:banana:
__________________
Please feel free to PM me about custom work, installations, and upgrades!

Eclipse Records - Streetcult Street Team

Last edited by Antivirus; 14 Aug 2006 at 07:48.
Reply With Quote
  #3  
Old 15 Jul 2006, 22:06
Kirk Y's Avatar
Kirk Y Kirk Y is offline
 
Join Date: Apr 2005
Sweet! I've never taken the time to figure this out on my own, thanks Revan!
__________________
Please feel free to re-use any of the code in any of my projects submitted to vB.org, so long as original attribution is retained.
Reply With Quote
  #4  
Old 30 Jul 2006, 20:07
King Kovifor's Avatar
King Kovifor King Kovifor is offline
 
Join Date: Nov 2004
Real name: Jeremy
I fixed my problems.
__________________
Do not request support through any other means except the forums.

Useful Post With Links on Learning How To Develop vBulletin Plugins

Latest Modification: Stop Forum Spam Integration

Last edited by King Kovifor; 31 Jul 2006 at 19:19.
Reply With Quote
  #5  
Old 02 Aug 2006, 22:04
Sean S's Avatar
Sean S Sean S is offline
 
Join Date: Jan 2004
Real name: Sean
you are my hero x 2 . very neat tutorial Revan, thank you.

I also found something else that I thought would be a good addition for those that might run into the same problem.

The problem I faced was that if I didn't want the navbar template included in the page, I would get a javascript error and the jump to page option did not open.

So if you have a page that does not include the $navbar, put this instead of it and it should get rid of the error and also show the jump to page input box.


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.


Last edited by Sean S; 02 Aug 2006 at 22:35. Reason: Automerged Doublepost
Reply With Quote
  #6  
Old 12 Aug 2006, 17:45
Princeton's Avatar
Princeton Princeton is offline
 
Join Date: Nov 2001
Real name: Joe Velez
Great article ... thanks for sharing with the community
__________________
Latest Articles:
Liquid Layout = Less Ad Revenue?
How to Monetize Your Site
Improve Web Page Performance
How To Write For The Web


If it needs instructions, there's room for improvement.
Give users what they actually want, not what they say they want. And whatever you do, don't give them new features just because your competitors have them!
Reply With Quote
  #7  
Old 16 Aug 2006, 19:09
Antivirus's Avatar
Antivirus Antivirus is offline
 
Join Date: Sep 2004
oh my, I am paginating everything now!!!
__________________
Please feel free to PM me about custom work, installations, and upgrades!

Eclipse Records - Streetcult Street Team
Reply With Quote
  #8  
Old 25 Aug 2006, 06:25
harmor19 harmor19 is offline
 
Join Date: Apr 2005
Real name: Andrew Harmor
Thank you. It works beautifully!
Reply With Quote
  #9  
Old 24 Sep 2006, 19:11
Surviver Surviver is offline
 
Join Date: Feb 2006
Real name: Julian
Thank you, great Tutoril !
Reply With Quote
  #10  
Old 16 Aug 2007, 14:59
X Quiz X Quiz is offline
 
Join Date: Apr 2004
thanks, but what about in admincp? how can we paginate the results?
Reply With Quote
  #11  
Old 17 Aug 2007, 06:58
Mixtoon's Avatar
Mixtoon Mixtoon is offline
 
Join Date: Aug 2007
Real name: Khalid
Originally Posted by X Quiz View Post
thanks, but what about in admincp? how can we paginate the results?
I'm asking the same question!
__________________
An Arabic community.
Reply With Quote
  #12  
Old 13 Sep 2007, 12:27
Davidinh Davidinh is offline
 
Join Date: Apr 2005
how to Paginate your results in AdminCP page

thanks,
Reply With Quote
  #13  
Old 27 Mar 2008, 20:01
TonyLuong TonyLuong is offline
 
Join Date: Nov 2006
I use this How To exact the way you layout and I got the Navigation to show up; I can Navigate through pages; however, I notice the IE status bar has error message "done, but with errors on page". I click on it to view the error detail, it is "'null' is null or not an object". If I comment out the construct_page_nav function call then the page disply just 1 page without the Navigation and no error produce; this makes me think the error comes from the Navigation.

Also I notice the end of has an arrow down image; when click on the image it suppose to show up a box says "Go to page...", you would then enter a page number and click "go" to go to that page; however, the arrow down on mine is not clickable; I click on it and nothing happens.

Anyone know what I might have done wrong or missing?
Reply With Quote
  #14  
Old 13 Jan 2010, 02:35
businessmeet businessmeet is offline
 
Join Date: May 2009
Edit: Sorry, I forgot I clicked the link from this page originally:
http://www.vbulletin.org/forum/showthread.php?t=221670 brought me here. LOL! *Forehead slap moment*

Last edited by businessmeet; 13 Jan 2010 at 03:16.
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Article Options

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


New To Site? Need Help?

All times are GMT. The time now is 09:18.

Layout Options | Width: Wide Color: