For the select:
<?php
$result= mysql_query('SELECT DISTINCT Year FROM MonthlySales');
$sel = "\n<select name=\"mySelect\">";
while($row= mysql_fetch_assoc($result)) {
$op = htmlspecialchars($row['Year']);
$sel .= "\n\t<option value=\"$op\">$op</option>";
}
$sel .= "\n</select>\n";
?>
Then just place the $selvariable into your html table
diafol
Keep Smiling
10,842 posts since Oct 2006
Reputation Points: 1,675
Solved Threads: 1,536
Skill Endorsements: 61
The dropdown will need to be submitted from its form. You pick this up in a different page (the form handler) or the same page if you must by the variable $_POST['mySelect'].
Clean this variable with mysql_real_escape_string() or intval() if you're passing an integer (year) and then use it in your SQL that retrieves the html table for that selected year.
Your form (e.g.):
<form method="post">
<label for="mySelect">Choose the year:</label>
<?php echo $sel;?>
<input type="submit" value="Filter Results" name="submityear" id="submityear" />
</form>
diafol
Keep Smiling
10,842 posts since Oct 2006
Reputation Points: 1,675
Solved Threads: 1,536
Skill Endorsements: 61
Yes as I said you must clean the var first.
diafol
Keep Smiling
10,842 posts since Oct 2006
Reputation Points: 1,675
Solved Threads: 1,536
Skill Endorsements: 61