我想创建一个下拉列表,允许用户选择开始和结束“年、月、日”,如下所示。当页面更新时,选项将恢复为“原始”选项。当页面更新时,如何允许这些选定的值保存并保留?
<?php
if (isset($_POST['action']))
{
$action = $_POST['action'];
$startyear = $_POST['startyear'];
$startmonth = $_POST['startmonth'];
$startday = $_POST['startday'];
$endyear = $_POST['endyear'];
$endmonth = $_POST['endmonth'];
$endday = $_POST['endday'];
}
else
{
$action = "";
if (!isset($_POST['startyear']) || !isset($_POST['startmonth']) || !isset($_POST['startday'])
|| !isset($_POST['endyear']) || !isset($_POST['startmonth']) || !isset($_POST['startday']))
{
$startyear = "";
$startmonth = "";
$startday = "";
$endyear = "";
$endmonth = "";
$endday = "";
}
else
{
$startyear = $_POST['startyear'];
$startmonth = $_POST['startmonth'];
$startday = $_POST['startday'];
$endyear = $_POST['endyear'];
$endmonth = $_POST['endmonth'];
$endday = $_POST['endday'];
}
}
if ($action == "update")
{
echo "<h3>Start: $startyear-$startmonth-$startday | End: $endyear-$endmonth-$endday</h3>";
}
else
{
if ($startyear == "" || $endyear == "")
{
// something belongs here...not sure
}
echo "<h3>Start: $startyear-$startmonth-$startday | End: $endyear-$endmonth-$endday</h3>";
?>
开始/结束年、月、日的选择在这里:
<form name='update' action='testing.php' method='POST'>
Start: <select name='startyear'>
<option value="1">2012</option>
<option value="2">2011</option>
<option value="3">2010</option>
<option value="4">2009</option>
<option value="5">2008</option>
<option value="6">2007</option>
<option value="7">2006</option>
<option value="8">2005</option>
<option value="9">2004</option>
<option value="10">2003</option>
<option value="11'>2002</option>
<option value="12">2001</option>
<option value="13">2000</option>
<option value="14">1999</option>
<option value="15">1998</option>
</select>
<select name='startmonth'>
<option value="1">01</option>
<option value="2">02</option>
<option value="3">03</option>
<option value="4">04</option>
<option value="5">05</option>
<option value="6">06</option>
<option value="7">07</option>
<option value="8">08</option>
<option value="9">09</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
</select>
<select name='startday'>
<option value="1">01</option>
<option value="2">02</option>
<option value="3">03</option>
<option value="4">04</option>
<option value="5">05</option>
<option value="6">06</option>
<option value="7">07</option>
<option value="8">08</option>
<option value="9">09</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
<option value="21">21</option>
<option value="22">22</option>
<option value="23">23</option>
<option value="24">24</option>
<option value="25">25</option>
<option value="26">26</option>
<option value="27">27</option>
<option value="28">28</option>
<option value="29">29</option>
<option value="30">30</option>
<option value="31">31</option>
</select>
<br>
End:<select name ='endyear'>
<option value="1">2012</option>
<option value="2">2011</option>
<option value="3">2010</option>
<option value="4">2009</option>
<option value="5">2008</option>
<option value="6">2007</option>
<option value="7">2006</option>
<option value="8">2005</option>
<option value="9">2004</option>
<option value="10">2003</option>
<option value="11'>2002</option>
<option value="12">2001</option>
<option value="13">2000</option>
<option value="14">1999</option>
<option value="15">1998</option>
</select>
<select name='endmonth'>
<option value="1">01</option>
<option value="2">02</option>
<option value="3">03</option>
<option value="4">04</option>
<option value="5">05</option>
<option value="6">06</option>
<option value="7">07</option>
<option value="8">08</option>
<option value="9">09</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
</select>
<select name='endday'>
<option value="1">01</option>
<option value="2">02</option>
<option value="3">03</option>
<option value="4">04</option>
<option value="5">05</option>
<option value="6">06</option>
<option value="7">07</option>
<option value="8">08</option>
<option value="9">09</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
<option value="21">21</option>
<option value="22">22</option>
<option value="23">23</option>
<option value="24">24</option>
<option value="25">25</option>
<option value="26">26</option>
<option value="27">27</option>
<option value="28">28</option>
<option value="29">29</option>
<option value="30">30</option>
<option value="31">31</option>
</select>
<input type='submit' value='Compare'/>
</form>
<?php
}
?>