Peyman abdollahy
Peyman abdollahy

Reputation: 829

advance search with php with pagination?

I have some users with some info like their countery_id, their education_id, their degree_id etc. and I want to fetch them based on this info in a page with pagination. I know how to do this with $_GET but I want my URL to be clean and I want use $_POST for send users info and fetch them. and for pagination I use get method like this , ?pg=1

The problem is when I send form and fetch users in first page, there is no problem but when I click for second page. I lose my $_POST variables and can't fetch second page result. what is the best answer for this situation?

Upvotes: 1

Views: 252

Answers (1)

gotha
gotha

Reputation: 489

Make the next button to be actually part of a form that submits by post.

<form method="post" action="page.php?pg=2" id="myForm">
    <input type="hidden" name="education_id" value="<?=$education_id;?>" />
    <!-- and so on for the rest of the properties -->
    <input type="submit" value="Next" /> 
</form>

or you do not want submit button, create the form and put a link like this one somewhere.

<a href="javascript:;" onclick='$("#myForm").submit()'> Next </a>

Edit: As you can see this solution is not elegant, but it will work. Using $_POST is not recommended, $_GET is better because of bookmarking, etc

Upvotes: 1

Related Questions