kat32 Posted August 24, 2009 Share Posted August 24, 2009 I found this script on the net and used it to query the database and paginate results. Problem I have is that when navigating between pagination menu it does not 'remember' the checkboxes selected (e.g. tick checkbox on page 1 then navigate to page 2 then back to page 1, whatever was selected is not there, it has to be reselected). How do I modify this to work to remember what was selected on previous pages ... Thanks <html><head><title></title> <LINK href="style/style.css" rel=stylesheet type=text/css> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head><body bgcolor="#DDFFDD"> <?php $var1 = languages;//subject $var2 = debates;//category echo "<form name=\"form1\" method=\"post\" action=\"generate_rubric.php\">"; echo "<p class=\"font2\"><b>Criteria and Levels for:</b> </p>"; echo "<p class=\"font2\"><b>Subject:</b> " .$var1 ."<br>"; echo "<p class=\"font2\"><b>Category:</b> " .$var2 ."<p>"; include 'inc/db_subject.php'; // how many rows to show per page $rowsPerPage = 20; // by default we show first page $pageNum = 1; // if $_GET['page'] defined, use it as page number if(isset($_GET['page'])) { $pageNum = $_GET['page']; } // counting the offset $offset = ($pageNum - 1) * $rowsPerPage; $result = mysql_query("SELECT id, criteria, level1, level2, level3, level4, level5 FROM $var1 WHERE (category = '$var2') LIMIT $offset, $rowsPerPage") or die('Error, query failed'); // print the random numbers while($row = mysql_fetch_array($result)) { echo "<table width=\"600\" border=\"0\" cellspacing=\"0\" cellpadding=\"4\" bgcolor=\"#DDFFDD\" class=\"tablemain\">"; echo "<tr><td valign=\"middle\" width=\"20\">"; echo "<input name=\"sendto[]\" type=\"checkbox\" id=\"sendto[]\" value=\""; echo $row['id']; echo "\" /></td>"; echo "<td valign=\"middle\" width=\"572\"><b>Criteria:</b> "; echo $row['criteria']; echo "</td></tr><tr><td colspan=\"2\">"; echo "<table width=\"600\" border=\"1\" cellspacing=\"0\" cellpadding=\"2\" bgcolor=\"#DDFFDD\" class=\"tablemain\"><tr bgcolor=\"#FF9900\">"; echo "<td width=\"114\"><div align=\"center\">Level 1</div></td>"; echo "<td width=\"114\"><div align=\"center\">Level 2</div></td>"; echo "<td width=\"114\"><div align=\"center\">Level 3</div></td>"; echo "<td width=\"114\"><div align=\"center\">Level 4</div></td>"; echo "<td width=\"114\"><div align=\"center\">Level 5</div></td></tr><tr>"; echo "<td width=\"114\">" .$row['level1'] ."</td>"; echo "<td width=\"114\">" .$row['level2'] ."</td>"; echo "<td width=\"114\">" .$row['level3'] ."</td>"; echo "<td width=\"114\">" .$row['level4'] ."</td>"; echo "<td width=\"114\">" .$row['level5'] ."</td>"; echo "</tr></table></td></tr>"; echo "</table>"; echo "<p>"; } echo "<p><input type=\"submit\" value=\"Create Rubric\"> "; echo "<input type=\"reset\" name=\"Reset\" value=\"Reset\">"; echo "<p></form>"; // how many rows we have in database $query = "SELECT COUNT(id) AS numrows FROM $var1"; $result = mysql_query($query) or die('Error, query failed'); $row = mysql_fetch_array($result, MYSQL_ASSOC); $numrows = $row['numrows']; // how many pages we have when using paging? $maxPage = ceil($numrows/$rowsPerPage); // print the link to access each page $self = $_SERVER['PHP_SELF']; $nav = ''; for($page = 1; $page <= $maxPage; $page++) { if ($page == $pageNum) { $nav .= " $page "; // no need to create a link to current page } else { $nav .= " <a href=\"$self?page=$page\">$page</a> "; } } // creating previous and next link // plus the link to go straight to // the first and last page if ($pageNum > 1) { $page = $pageNum - 1; $prev = " <a href=\"$self?page=$page\">[Prev]</a> "; $first = " <a href=\"$self?page=1\">[First Page]</a> "; } else { $prev = ' '; // we're on page one, don't print previous link $first = ' '; // nor the first page link } if ($pageNum < $maxPage) { $page = $pageNum + 1; $next = " <a href=\"$self?page=$page\">[Next]</a> "; $last = " <a href=\"$self?page=$maxPage\">[Last Page]</a> "; } else { $next = ' '; // we're on the last page, don't print next link $last = ' '; // nor the last page link } // print the navigation link echo "Test"; echo $first . $prev . $nav . $next . $last; ?> </body> </html> Quote Link to comment Share on other sites More sharing options...
tekrscom Posted August 24, 2009 Share Posted August 24, 2009 What I would do in that instance probably is put a Javascript onChange handler on the checkboxes along with its value being assigned by a SESSION variable... then when you check one of them, it posts it and assigns its value to a SESSION variable to be called again on that checkbox... Hope all of that made sense... Quote Link to comment Share on other sites More sharing options...
kat32 Posted August 24, 2009 Author Share Posted August 24, 2009 What I would do in that instance probably is put a Javascript onChange handler on the checkboxes along with its value being assigned by a SESSION variable... then when you check one of them, it posts it and assigns its value to a SESSION variable to be called again on that checkbox... Hope all of that made sense... please give code examples, thanks. Quote Link to comment Share on other sites More sharing options...
tekrscom Posted August 24, 2009 Share Posted August 24, 2009 Well, I'm not going to go into testing it all, but something like this should work... if (isset($_POST['MailingList'])) {$_SESSION['MailingList'] = 1;}else{$_SESSION['MailingList'] = 0;} echo '<input type="checkbox" name="MailingList" '; if($_SESSION['MailingList'] == 1){echo 'checked';} echo 'onClick="submit();">'; You could do something like that for each of the checkboxes... there's probably a better way, but this is how I would do it right off the top of my head... Quote Link to comment Share on other sites More sharing options...
kat32 Posted August 24, 2009 Author Share Posted August 24, 2009 when I click the submit button, it will display the values of the checkbox that I checked in all pages. help please.. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.