I have a number of select option which I paginated to display 5 select option per page and this works fine like this
<form method="post" action="sel.php">
<?php
---------------------------------
//Pagination script here
----------------------------------------
//Here, I retrieve some values from database
$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))
{
//Here, I display the select option while the above values are retrived
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.80 01 Both Team to Score (YES)'>1.90 Both Team to Score (YES)</option>
<option value='1.85 02 Both Team to Score (NO)'> 1.85 Both Team to Score (NO)</option>
<option value='1.90 03 Over2.5(Total Goals)'>1.90 Over2.5(Total Goals)</option>
<option value='1.80 04 Under 2.5(Total Goals)'>1.80 Under 2.5(Total Goals)</option>
<option value='1.35 05 Over 1.5 (Total Goals)'>1.35 Over 1.5 (Total Goals)</option>
<option value='2.60 06 Under 1.5 (Total Goals)'>2.60 Under 1.5 (Total Goals)</option>
<option value='2.05 07 Draw(First Half)'>2.05 Draw(First Half)</option>
<option value='1.55 08 Either Team Win (First Half)'>1.55 Either Team Win (First Half)</option>
<option value='3.70 09 Draw(Full Time)'>3.70 Draw(Full Time)</option>
<option value='1.20 10 Either Team Win (Full Time)'>1.20 Either Team Win (Full Time)</option>
<option value='1.90 11 Even(Total Goals)'>1.90 Even(Total Goals)</option>
<option value='1.90 12 Odd(Total Goals)'>1.90 Odd(Total Goals)</option>
</select>".
"<hr>";
}//end While
------------------------------
$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
-----------------------------------
?>
<br /><input type="submit" name="play" value="Calculate Bet" />
</form></div>
Here is the problem, If a user select any amount of option on page 1, and click page 2, and also select options on page 2, selects nothing on page 3 and proceed to submit form, only the option selected on the last selection page i.e page 2 is retrieved on the form processing page. How do i pass the values of option selected in all the pages down to the form processing page and not just the values selected on the last page?
There are several ways to pass the selected option.
You can pass the selected values in the URL e.g. example.com/?option=true&option2=true
And can retrieve i.e check if the option was selected or not using isset() function Eg. if(isset($_GET["option"])) { //do some stuffs }
or if($_GET["option"]=="true") { //do some stuffs }
There is very minor difference in the above mentioned method, get and the post one. YOu need to change $_GET
to $_POST
in each cases
Other two methods you can use cookies and session which I don't recommend