Jump to content

$_POST array being thwarted by pagination


mrherman

Recommended Posts

PHP learner.  This is a "learning" script that I'm working on.

 

I have a simple html table that displays rows from mysql. 

Each row has a unique ID.

Each row begins with a checkbox, so that the user can select the row (method POST)

There is a rudimentary pagination script, so that 20 records are displayed on each page.

There are pagination links so that the user can select pages of records to view.

 

PROBLEM:

Since I've put in the pagination code, the selections made on each page are lost as the user moves from one page to another.  For example, if the user selects 5 records on page 1, and 4 records on page 2 -- when the select button is finally clicked, only the latest 4 records (from page 2) are in the $_POST array.

 

How can I make the $_POST array accumulate all user selections across pages?

 

Thanks!

The way I can now come up would be like

with js make those urls of pages act as submit button

<a ... onclick="document.myform.elements['page'].value=1; document.myform.submit();return false;">[1]</a>

<a ... onclick="document.myform.elements['page'].value=2; document.myform.submit();return false;">[2]</a>

 

lets say u work with view.php so it should look smth like

//if user clicked submit button
if(isset($_POST['submit_button']))
{
//store data in database or what ever u wanna todo
//print success message
}
else
{
echo "<form action='view.php' method='post'>";
echo "<input type='hidden' value=".($_POST['page']+1)." name='page'>";
echo "<table>";

//if user cliked on page link it means that we have submited form and we may have some boxes checked so save values of that preview page in hidden fields
if(isset($_POST['box']))
{
   foreach($_POST['box'] as $value)
   {
      echo "<input type='hidden' name='box[]' value='$value'>";
   }
}

//here we echo data from db ps: use like this LIMIT x, 20 where x = $_POST['page'] and not $_GET['page']
while($row ...)
{
echo "<input type='chekcbox' name='box[]' value='$row[id]'>";
}
//<>
echo "</table>";
echo "<input type='submit' name='submit_button' value='go santa'>";
echo "</form>";
//echo your page number here with onclick event as I mention before
}

 

so here it is I hope the idea will work :)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.