Pagination problem

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);
}


Well,you should distinguish between the two operations submit or click a pagination link at first.For example,when you click a pagination link,then the link must like ‘…/your_page?checkboxstring=yourcheckboxstring&s=your_selected_page_id’,so the value of isset($_GET[‘s’]) will be true.When you submit,you only post checkboxstring data,then the value of isset($_GET[‘s’]) will be false.By the way,the page will load with the new results.

blue_sky, thank you for your input.

When you submit,you only post checkboxstring data,then the value of isset($_GET[‘s’]) will be false

But this is only true the first time a checkbox is selected. Once I’ve selected a checkbox and have paged through a number of pagination links, $_GET[‘s’] will have a value, which means the next time a checkbox is checked, $start will never be 0. I’ve tried to add $start=0 below if (isset($checkboxstring)) but that didn’t 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.

I couldn’t believe that!Could you please post more the code that you’re using?