I've got a table with dates:
id,datefield,dayfield,monthyearfield
1,2012-05-01,Tuesday,May-2012
2,2012-05-02,Wednesday,May-2012
I'm using a dropdownbox where I select DISTINCT monthyearfield. If the month is for instance Jun-2012 I want the dropdownbox to default to that when the page opens. I don't know how to do that. If I use a WHERE clause it only shows for instance Jun-2012. Currently it is defaulting to the first row, which is May-2012. I tried ORDER BY variable ($date_start1) but that is not working.
<?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 .= "
<option value='{$row2['id']}'>{$row2['monthyearfield']}</option>";
}
$dropdown .= "
</select>";
echo $dropdown;
echo "<input type=submit name=Submit value='Go'>";
$data1 = mysql_real_escape_string($_POST["myvalue"]);
echo "</form>";
?>