Hi all,
this code is used in a pagination script that includes a form with checkboxes to filter the query results. I’m having some difficulties, so please help where you can.
This is what happens:
I select a checkbox and submit the form
The page loads with the filtered results
I now click a pagination link to go to page 5 of the results
On page 5 I decide to click another checkbox. The form is again submitted.
The page will load with the new results but the problem is that the page remains on page 5, or whatever page I was on before another checkbox was selected.
The likely cause is the following code:
if (isset($checkboxstring)) {
if (isset($_GET['s'])) {
$start = $_GET['s'];
} else {
$start = 0;
}
If I click a checkbox the first time, $_GET[‘s’] has not been set, thus $start=0. Once I click on the links $_GET[‘s’] will have a value which is assigned to $start. This is necessary for the pagination to work. The problem is that this $_GET[‘s’] value is still present when I select another checkbox. So the new results load on the same page instead of the first page.
The solution might be that whenever $checkboxstring has been set, the if (isset($_GET[‘s’])) code should start from the beginning again. But I don’t know how – with a loop?
I hope my explanation is adequate.
Thank you very much!
$checkboxstring comes from:
$arguments ='';
if (isset($_POST['food'])){
foreach ($_POST['food'] as $k) {
$arguments[] .= "favourite_food='$k'";
}
if(!empty($arguments)) {
$string = implode(' && ',$arguments);
}