1

I have form with a Select option that loops like this.

<form method="post" action="consel.php">
<?php
$sql = "SELECT * FROM games WHERE startunix > '$nowtime' ORDER BY starttime LIMIT $offset, $rowsperpage" ;
$retval = mysql_query($sql);
while($row = mysql_fetch_array($retval, MYSQL_ASSOC))
{
echo "<select name='gm[$row[gamecode]]' >
<option value=''>Select option</option>
<option value='01'>01</option>
<option value='02'>02</option>
<option value='03'>03</option>
<option value='04'>04</option>
</select>";
}
//Pagination Script Starts here
$range = 3;
// if not on page 1, don't show back links
if ($currentpage > 1) {
   // show << link to go back to page 1
   echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=1'>First Page |</a> ";
   // get previous page num
   $prevpage = $currentpage - 1;
   // show < link to go back to 1 page
   echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage'>Previous Page |</a> ";
} // end if 

// loop to show links to range of pages around current page
for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) {
   // if it's a valid page number...
   if (($x > 0) && ($x <= $totalpages)) {
      // if we're on current page...
      if ($x == $currentpage) {
         // 'highlight' it but don't make a link
         echo " [<b>$x</b>] ";
      // if not current page...
      } else {
         // make it a link
         echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$x'>$x</a> ";
      } // end else
   } // end if 
} // end for

// if not on last page, show forward and last page links        
if ($currentpage != $totalpages) {
   // get next page
   $nextpage = $currentpage + 1;
    // echo forward link for next page 
   echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$nextpage'>Next</a> ";
   // echo forward link for lastpage
   echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$totalpages'>| Last</a> ";
} // end if
/****** end pagination links ******/
?>
<br /><input type="submit" name="play" value="submit" />
</form>

I do not expect the user submit form on the first page but whatever drop down option the user selects gets lost on clicking the Next Page. the form thereby submits only the selected option in the next pages without remembering the selection in the previous pages. Kindly help out

scylla
  • 124
  • 9
  • 1
    add selected option to the url, just like you add the page number –  Jul 06 '15 at 21:26
  • 3
    If you can, you should [stop using `mysql_*` functions](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php). They are no longer maintained and are [officially deprecated](https://wiki.php.net/rfc/mysql_deprecation). Learn about [prepared](http://en.wikipedia.org/wiki/Prepared_statement) [statements](http://php.net/manual/en/pdo.prepared-statements.php) instead, and consider using PDO, [it's really not hard](http://jayblanchard.net/demystifying_php_pdo.html). – Jay Blanchard Jul 06 '15 at 21:29
  • @JayBlanchard, I have that in mind. – scylla Jul 06 '15 at 21:30
  • typing? if you wrote that above adding another variable to the url should be trivial –  Jul 06 '15 at 21:31
  • I tried it earlier using $_GET, got empty Value on submission on the next page – scylla Jul 06 '15 at 21:34

0 Answers0