I'm trying to setup a page where users can choose the month and year of news articles, and then have all the articles displayed for that current month and year. And also, if no month/year is chosen, then display all the articles for the current month. I'm having some trouble and I don't know where I messed up as the code seems perfect to me. The code is below:
<?php
//Build Form
echo "<form action=\"$PHP_SELF\" method=\"post\" name=\"select_date\" id=\"select_date\">
<p align=\"center\" class=\"bodyTEXT\">Month:
<select name=\"m\">
<option value=\"January\">January</option>
<option value=\"February\">February</option>
<option value=\"March\">March</option>
<option value=\"April\">April</option>
<option value=\"May\">May</option>
<option value=\"June\">June</option>
<option value=\"July\">July</option>
<option value=\"August\">August</option>
<option value=\"September\">September</option>
<option value=\"October\">October</option>
<option value=\"November\">November</option>
<option value=\"December\">December</option>
</select>
Year:
<select name=\"y\">
<option value=\"2003\">2003</option>
</select>
<input name=\"submit\" type=\"submit\" id=\"submit\" value=\"Go\">
</p>
</form>";
//Build Variables
$now_month = date(F);
$now_year = date(Y);
if (!isset($m)) {
$m = $now_month;
}
else {
$m = $_GET['m'];
}
if (!isset($y)) {
$y = $now_year;
}
else {
$y = $_GET['y'];
}
$d = "$y-$m";
//Display Articles
echo '<table width="600" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td>';
$display_title = mysql_query("SELECT id,date_FORMAT(date,'%m/%d/%Y at %l:%i:%s %p') AS date, title, teaser, news FROM news WHERE date = '$d' ORDER BY date DESC")
or die ("MySQL Error");
if (mysql_num_rows($display_title) > 0)
{
while ($row = mysql_fetch_array($display_title))
{
$id = $row ['id'];
$date = $row ['date'];
$title = $row ['title'];
$teaser = $row ['teaser'];
$news = $row ['news'];
echo "<p class=\"TITLE3\"><b><a href=\"news.php?id=$id\" class=\"bodynav\">$title</a></b><BR>Posted On $date<BR>$teaser</p>";
}
}
echo '</td>
</tr>
</table>';
?>