I need to query a date field (YYYY-MM-DD) in a table and get a distinct date format. Only problem is, I need the results to end up in a drop down.
Here's the current code, which displays multiple dates, since YYYY and MM might be the same, but DD are different, causing there to be two results.
$sql = "SELECT DISTINCT dte FROM table ORDER BY dte DESC";
$connection = mysql_connect($default->db_host, $default->db_user, $default->db_pass)
or die ("Couldn't connect to server.");
$db = mysql_select_db($default->db, $connection)
or die ("Couldn't select database.");
$sql_result = mysql_query($sql)
or die("Couldn't execute query.");
if (!$sql_result) {
echo "
<table width=$default->table_width border=\"0\" cellspacing=\"2\" cellpadding=\"2\" align=\"center\">
<tr align=\"left\">
<td>Contat Admin, something's a' miss!</td>
</tr>
</table>
<p>";
} else {
echo "
<FORM method=\"POST\" action=\"$default->quote_root_url/display.php\">
<select name=\"sel_record\">
";
while ($row = mysql_fetch_array($sql_result)) {
$dte = $row["dte"];
$timestmp = strtotime("$dte");
$datestr = date("F - Y", $timestmp);
echo "
<option value=\"$dte\">$datestr</option>
";
}
echo "
</select>
The above creates two items in the drop down because the days are different. Is there anyway to distinct the date, but allow the drop down to populate with the MM/YYYY?
Am I being clear?