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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With