Hi,
I am adding a pagination on the search result on my site in PHP and I encountered some problem. I hope somebody with more knowledge and experience could help me here.
I'll try to explain what I did in my program and what the problem is as simple and as clearly as I can.
I have 2 pages, one is called criteria.php and one is called results.php. criteria.php has some form controls like text fields
taking user inputs, like the following
Here's what criteria.php roughly looks like,
<html><head><title>test</title></head>
<body>
<form name="criteria_form" action="results.php" method="post">
<table>
<tr>
<td>criteria_1</td>
<td><input type="text" name="criteria_1" size"16"></td>
</tr>
<tr>
<td>criterial_2</td>
<td><input type="text" name="criteria_2" size="16"></td>
</tr>
<tr>
<td><input type="button" name="submit_button" value="submit"><td>
</tr>
</table>
</form>
</body>
</html>
Here's what results.php looks like,
<?PHP
$cur_page = $GET['page'];
if(!isset($GET['page'])){$cur_page = 1;}
$criteria_1 = $POST['criteria_1'];
$criteria_2 = $POST['criteria_2'];
$results = search($criteria_1, $criteria_2, $cur_page, NUM_PER_PAGE);
// NUM_PER_PAGE and search function are defined in some other file
?>
<html>
<body>
// loop through the $result and display them with pagination
</body>
</html>
I only listed 2 search criteria, but in my site, I have more.
If the current page is page 2, in the pagination, my "next" url link would be results.php?page=3 and "previous" url link is results.php?page=1. In order for each page to display properly, they have to get $criteria_1 and $criteria_2 and go through the search function.
But when I click the previous/next page, it won't get the $criteria_1 and $criteria_2 from the $_POST array. therefore the result won't be correctly displayed for results.php?page=2 or so on.
I hope I have described my problem clearly. Somebody with more knowledge please give me some advice to avoid the problem I have. You're help will be appreciated. thanks.