The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
[HOW TO - vB4] Paginating Results
Introduction Not very much has changed regarding how pagination works since vB 3.8, but quite enough to warrant an update of Revan's great tutorial, dating from 2006. Kudos to Revan. As Revan I assume you know your way around php and can understand at least roughfly what each bit of the code does. There'll be explanations, of course, but this is for coders and mod developers. The main work for pagination has to be done in the PHP-code, still no surprise there. Cleaning URL parameters We start off by cleaning the URL parameters that will tell our paginator how many entries to show per page and on which page of the resultset we're actually on PHP Code:
Counting results The next step is to count the number of resuts that our actual database query will return (this query we will meet later on - it's an example that will throw all users with no posts). PHP Code:
Settings & sanitizing Next we're off to do some settings: The first argument is our counting result. The last two arguments are the maximum number of results per page (100) and the default number of results per page (20). Note how the first argument is the result of the count query above. You can replace those with settings from the AdminCP by inserting the corresponding variables obviously. PHP Code:
Orientation - where are we? Now some stuff to determine on which page we're on and which results to show. Note how you have to provide the results of our initial count query: PHP Code:
The main query Now the query that throws all users with no posts - just an example, obviously. Note the LIMIT - this has to be added to the original query to delimit the resultset for the actual page PHP Code:
Constructing pagenav The last (but one) thing to do in the PHP code is to finally call the function to construct the actual page-nav and saving it's output to a variable for passing to the template.
PHP Code:
Registering pagenav for templates As with all variables in vB4, the newly created $pagenav has to be registered to be used inside the template: PHP Code:
Template code Now you just have to put the pagenav-code into your template, and we're done. Note that the id of the surrounding div should be changed to "pagination_bottom" or "pagination_top" accordingly. Code:
<vb:if condition="$pagenav"> <div id="pagination_top"> {vb:raw pagenav} </div> </vb:if> -c As of now (beta 3), there are still some issues that need to be resolved regarding pagination. They are minor and there should not be substantial changes, but be aware of that. For example, the setting of results shown per page does not work yet - 20 is hardcoded into the sanitizing function. |
#12
|
|||
|
|||
I would really appreciate it if somebody could help me out.
I've built a page that pulls row from a sql db. Now I need to paginate the page as there are too many rows for one page. I've followed the instructions as far as I can, changing only a few things, such as the sql queries. The php is now limiting the number of rows to the correct perpage number. I've added the pagenav code to my custom template, but no matter what I do, the pagenav doesn't show. Any help would be greatly appreciated. S1OPP |
#13
|
||||
|
||||
Quote:
|
#14
|
||||
|
||||
^^What he said
Good to know |
#15
|
|||
|
|||
no problem.
sightings.php PHP Code:
PHP Code:
|
#16
|
|||
|
|||
Worked it out now,
thanks. |
#17
|
||||
|
||||
Sorry, didn't come around to look at your code - but you working it out yourself is much better anyway
|
#18
|
|||
|
|||
Dont forget to use the & like this when passing additional attributes.
PHP Code:
This one seems to work at first but it does not when using the page number input: PHP Code:
|
#19
|
|||
|
|||
As of VB 4.0.3, I now have errors with page pagination on custom mods...
Example: http://test.8wayrun.com/media/c9-kogarasumaru With VB 4.0.2, it looked fine, but now the last 3 elements are shifted. |
#20
|
|||
|
|||
Only happens in Chrome... only with vb4.0.3
This is code... Code:
<vb:if condition="$pagenav"> <div id="pagination_top" style="float: right;"> {vb:raw pagenav} </div><br /><br /> </vb:if> |
#21
|
|||
|
|||
Just wanted to say thank you for this article on pagination, I was finally able to understand it thanks to your post. Here is my example for those who are still trying to understand maybe this helps.
PHP Code:
|
Благодарность от: | ||
cellarius |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|