Jump to content

Where to add pagination code


hadoob024

Recommended Posts

I've read several tutorials and a ton of posts, and the code for implementing pagination seems to be pretty similar (the methodology at least). Anyway, I see how the code works, but I'm not sure how to apply it to my site in particular. I have a page "search.php", that has all the form information and creates sessions and passes this information as hidden tokens (to prevent against abuse of my forms). It passes the info to "searchresults.php". "searchresults.php" has the following structure:

1) check SESSION variables (to prevent against CSR, session hijacking, and session fixation)
2) initialize my variables which will store the info passed from the form
3) check/screen info passed through POST and set my variables equal to these values
4) validate information
5) connect to db
6) create and format results of SQL search string based on form information and by using SQL ORDER command
7) query db
8) if results found, display them, if not, then display generic message
9) free resultset
10) clean up SESSION, close tables, end script

So this layout works fine right now, but I want to add pagination and I guess my question is where/how to implement the pagination code given the layout of my "searchresults.php" page? Will all the SESSION stuff that I have mess this up? Will my form variables keep getting reset in between pages? Will the query be able to be passed ok?
Link to comment
Share on other sites


[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]
1) check SESSION variables (to prevent against CSR, session hijacking, and session fixation)
2) initialize my variables which will store the info passed from the form
3) check/screen info passed through POST and set my variables equal to these values
4) validate information
5) connect to db
6) create and format results of SQL search string based on form information and by using SQL ORDER command
7) query db
8) if results found, display them, if not, then display generic message
9) free resultset
10) clean up SESSION, close tables, end script[/quote]


Here are classes to install for pagination. It is pretty simple.

[a href=\"http://www.ecreate.co.uk/diy/pagination.php\" target=\"_blank\"]http://www.ecreate.co.uk/diy/pagination.php[/a]

To use this classes you will have to do somme change :
5 bis) Do a query tha count the number of result you have with your parameter
6) change your query to get just the number of results you want per pages ie : LIMIT $startRow, 20
9 bis) put link or a form that send to the next or previous pages.

The actuel code use links to change pages so you have the parameters appearing in your URL but I suppose it is pretty easy to change it for buttons with a form and post method. So then you can send back all your session variables.
Link to comment
Share on other sites

OK. I think I understand what you're saying. The only thing I'm not sure of is how to handle the links for previous/next pages. Can I get it to load a separate page instead? Right now, if I try to reload my "searchresults.php" page, I think my security/error handler won't allow for it. I guess I want to know if I can somehow use a separate page to handle the pagination instead of my main "searchresults.php" page?
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.