I have a form with a Select option, that loops and uses pagination to break it into five Select options per page.
But whenever a user selects options on several different pages, only the options selected on the last page before submitting the form are processed.
Research on this issue has been suggesting using AJAX or Javascript.
Any idea, how i can go about it - if possible using php alone.
<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 "<div align='center'><span class='style3'>{$row['home']} VS ".
"{$row['away']} </span></div>".
"<font color='#000000' size='2'>{$row['country']} | {$row['league']} | Time:{$row['starttime']} </font> <br> ".
"<select name='gm[$row[gamecode]|$row[starttime]|$row[home]|$row[away]]' >
<option value=''>Select option</option>
<option value='1'>YES</option>
<option value='2'> NO</option>
<option value='3'>Total Goals</option>
<option value='4'>Total </option>
<option value='5'>Goals</option>
</select>".
"<hr>";
}
/****** building the pagination links ******/
$range = 3;
if ($currentpage > 1) {
echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=1'>First Page |</a> ";
$prevpage = $currentpage - 1;
echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage'>Previous Page |</a> ";
}
for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) {
if (($x > 0) && ($x <= $totalpages)) {
if ($x == $currentpage) {
echo " [<b>$x</b>] ";
} else {
echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$x'>$x</a> ";
}
}
}
if ($currentpage != $totalpages) {
$nextpage = $currentpage + 1;
echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$nextpage'>Next</a> ";
echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$totalpages'>| Last</a> ";
}
/****** end build pagination links ******/
?>
<input type="submit" name="play" value="submit" />
</form>
If not the Submit, but the Next button is selected, the expected $_POST['gm'] of the options selected on the first/earlier page(s) is lost. Only the options selected on the page, where the Submit button was selected, are processed.
But I want all the options selected on all the pages together to be processed.