在下拉框中的起始行值我有使用日期表:設置在PHP
ID,的DateField,dayfield,monthyearfield
1,2012-05-01,星期二,五月-2012
2,2012-05-02,週三,5月2012
我使用的是dropdownbox,我選擇DISTINCT monthyearfield。例如,如果該月份是2012年6月,我希望下拉框默認爲頁面打開時。我不知道該怎麼做。如果我使用WHERE子句,它只會顯示2012年6月的情況。目前它默認爲2012年5月的第一行。我嘗試了ORDER BY變量($ date_start1),但這不起作用。
<?php
$date_start1 = "Jun-2012"; //just for testing purposes, will change later so that it gets the current Month.
echo $date_start1;
$sql2 = "SELECT DISTINCT monthyearfield FROM trn_cal";
$res2 = mysql_query($sql2);
echo "<form method='post'>";
$dropdown = "<select name='myvalue'>";
while ($row2 = mysql_fetch_assoc($res2)) {
$my = $row2['monthyearfield'];
$dropdown .= "\r\n<option value='{$row2['id']}'>{$row2['monthyearfield']}</option>";
}
$dropdown .= "\r\n</select>";
echo $dropdown;
echo "<input type=submit name=Submit value='Go'>";
$data1 = mysql_real_escape_string($_POST["myvalue"]);
echo "</form>";
?>