PHP Forums Archive

Pagination of search results using form input

Tags: variables, form method

denton posted on 2009-05-04 20:59:20 #

Thanks for the code, it's proved really useful. However, I've come across a problem - it's probably more to my lack of knowledge than your code as I'm fairly new to web coding but any help would be appreciated.

When I query the database using the results posted from a form, the pagination works initially i.e. for the first 10 records but when I click on the 2 hyperlink for the second page of results it loses the $_POST variable and returns to the full dataset with the undefined index error at the top.

What is the best way of keeping these variables available for the second (and further) pages? I've messed around with $_SESSION variables but can't quite get it to work.

Thanks

Comments / discussions

Olaf posted on 2009-05-05 07:07:27 #

use GET as form method...

denton posted on 2009-05-05 17:30:28 #

So simple! Thanks.

pets2soul posted on 2011-02-14 03:31:06 #

Dear Olaf,

Thank you for this great class, it's really easy to use and to configure, it saved my butt.

However, I'm having the similar question here. I've got MyPagina to work with GET for my search form, but it gives my web page a ugly URL, is there any way to work around it making it POST enabled?

I've tried session, but it doesn't seem to work...

Thank you again, and Happy Valentine's Day!

Olaf posted on 2011-02-14 20:45:59 #

Hi pets2soul,

I'm sorry this is how it works, if you like to combine pagination links and a form you need to use GET as the method. There is no other way. If you're worried about the URL, than read this article.

pets2soul posted on 2011-02-15 00:51:13 #

Thank you for the quick reply and the information, I'll study further into it!