Hi,
I have a table and it has many data, so there are many page numbers on a web page.
When I click a 'Edit' button on my web page, it goes to detail page.
What I want to accomplish is that I want to go back to previous page, not the first page.
For example, if I am viewing the 5th page in the pagination, then click a button to edit details, then click the 'Go Back' button, it goes to the first table page, not the 5th page.
How can I go back to previous page?
Can I do this by PHP, or Javascript?
Please advise me.
Thanks.
How can I go back to previous page in php pagination?
- Edited
The general purpose way of doing this is to build each link with any existing get parameters (start with a copy of the existing $_GET
data) and add any new/changed get parameters that your process needs (you would add an 'id=x' parameter to indicate which record you are editing and possibly an 'action=edit' parameter.) Then on the edit page, you would build a 'Go Back' link without the get parameters that you added in the above. This will leave you with the pagination page number and any previous get parameters in the link.
If you build the pagination links in the same way, starting with a copy of any existing get parameters, your code will work if there is for an example a search term that is an input to the pagination code.
To get a post method form to propagate any existing get parameters, just leave the action='...' attribute out of the form tag.
An easy way of building the query string part of links is to use http_build_query() (this also urlencodes the values so that they won't break the url.)