user2521365
user2521365

Reputation: 141

php get the post data when using pagination script

I have a page called mainPage.php that contain a pagination script which displays a list of pages.

 [1][2][3][4][5] 

the pagination works fine but when I go to the next page the post data disappear.

for($i=1;$i<=$totalPage;$i++)
{
if($page==$i)
{
echo ' <input  type="button" value="'.$i.'"> ';
}
else
{
echo '<a href="mainPage.php='.$i.'"> <input type="button" value="'.$i.'"> </a>';
}}

is there any way to get the post data to the next page number after clicking this link:

 <a href="mainPage.php='.$i.'"> 

without the form.

Upvotes: 4

Views: 2365

Answers (3)

Avinash Babu
Avinash Babu

Reputation: 6252

You can do your job by using the GET method instead of post.If you want to make it in post request you need to do it seperate for each one.

Upvotes: 0

deceze
deceze

Reputation: 522195

No, it's not possible. When a form is submitted (with method=post) to the server, that's one POST request. If you want to make another POST request, you need to make another POST request. If you click a link, that's not a POST request.

I'm assuming your scenario is something like a search form, which is submitted via POST and which returns several pages of results. In this case, POST is misused anyway. An HTTP POST request should be used for altering data on the server, like registering a new user or deleting a record. Just a search form is not data alteration, it's just data retrieval. As such, your form should be method=get. That will result in a URL with the form values as query parameters:

mainPage.php?search=foobar

You can then trivially create pagination URLs from that:

printf('<a href="mainPage.php?%s">...', http_build_query(array('page' => $i) + $ _GET));

Which will result in:

mainPage.php?search=foobar&page=2

This way all your requests are self contained GET queries.

Upvotes: 2

jkumar
jkumar

Reputation: 32

try <a href="mainPage.php?page='.$i.'"> and get page no. using $_GET['page'];

Upvotes: 0

Related Questions