0

I have a search form regarding property search having some elements on which search will give results. eg area,location,city,no of bedrooms etc. once the form is submitted i can get the values of all form elements by means of $_post. Problem is that when i will implement paging, then how will i get the values of elements on next pages? should i use some sort of global variables/array or sessions? what do you recommend?

1
  • That depends entirely on how you store your data. Is it stuffed in an array? In a database? Commented Nov 22, 2010 at 8:04

3 Answers 3

1

To get the values of $_post on next page you have to pass that $_post values in pagination link.

Say for example you have one input field named as search on which you are performing search. so you have to pass $_POST['search'] on each pagination link.

  <a href='search.php?page=2&search="'. $_POST['search'].'"'>Page 2</a>

Now on Page 2, you can get $_GET['search'] and use it in your query

==============================================================

You can use session also

when you get your $_Post values after submit, start session and save it in session variable. In that case you dont have to pass that value in Pagination link

session_start();
$_SESSION['search'] = $_POST['search'];

Now you can directly use $_SESSION['search'] value in your query.

But for every new search make this session variable empty, so if search field do not have any search value then it dont search in database with its older value.

Sign up to request clarification or add additional context in comments.

2 Comments

what should i do to show last page. i mean if my search results in 7 pages, how would i show page1 page2 .... page7
First calculate total number of records with its search criteria. Then divide it with record per page. So you will get Total Pages to show. say for eg total number of record = 30; record per page = 10; So pages will be 3. Now use for loop to show links for(i=1;i<=3;i++){ <a href='search.php?page="'.$i.'"&search="'. $_POST['search'].'"'>Page $i</a> }
0

I recommend that you, in your mysql-query use LIMIT. Such as for the first page, if you want 10 results:

SELECT * FROM searchtable LIKE %%WHATEVER%% LIMIT 0,10

This will limit the results to 10. For page 2 you sage:

SELECT * FROM searchtable LIKE %%WHATEVER%% LIMIT 11,20

Of course what you are going to do is set the limit as a variable from PHP. Hope this helps!

Comments

0

use 2 search queries, 1st as
select count(1) from _table_ WHERE _where_
and second one as
select _fields_ from table where _where_ LIMIT _limit_
where _limit_ is $pagenum*$itemsPerPage, ($pagenum+1)*$itemsPerPage

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.