mrherman Posted February 12, 2010 Share Posted February 12, 2010 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! Link to comment https://forums.phpfreaks.com/topic/191840-_post-array-being-thwarted-by-pagination/ Share on other sites More sharing options...
yozyk Posted February 12, 2010 Share Posted February 12, 2010 Pagination script based on PHP or JS ? Probably, you need use SESSION. P.S. I think it's not good idea make multipage submit. Link to comment https://forums.phpfreaks.com/topic/191840-_post-array-being-thwarted-by-pagination/#findComment-1011159 Share on other sites More sharing options...
sader Posted February 12, 2010 Share Posted February 12, 2010 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 Link to comment https://forums.phpfreaks.com/topic/191840-_post-array-being-thwarted-by-pagination/#findComment-1011168 Share on other sites More sharing options...
mrherman Posted February 12, 2010 Author Share Posted February 12, 2010 OK, thanks SADER and YOZYK -- That will get me off in the right direction. Yes, I'm just using PHP, so Javascript is Greek to me. Thanks for your time! Link to comment https://forums.phpfreaks.com/topic/191840-_post-array-being-thwarted-by-pagination/#findComment-1011177 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.