I’m trying to add paging functionality to a search items page. so I have added a pager with UL as
echo '<ul>';
for($i=1; $i<=$pageCount; $i++)
{
echo '<li><a href="' . $_SERVER['PHP_SELF'] . '?page=' . $i . '">' . $i . '</a>';
}
echo '</ul>';
When I click on a Page No in Pager, I can get the page number clicked on by
if (isset($_GET['page']))
{
$pageNo = $_GET['page'];
}
but I can not retain the text entered by the user to search items. I tried $_POST['txtSearchText'] but it does not retain the value after the page refreshed.
Is there a way to retain the from values (without using session) after self loading the page by hyperlink click?
You will either have your links submit a hidden form with your search parameters, or you serialize them as parameters to your query string to send along with the page number.
In the first case you need Javascript (so your “A” link will in fact set a hidden field in the form with the appropriate page number to go to, and submit the form).
In the second case you do not need it, but you make the query string less human-friendly.
Otherwise there is session (you can save your search in a session object and maybe use a token in your paging links, in order to allow several pages open at once) or even cookies.