Dropdown reload SQL query
Posted: Thu Oct 14, 2010 10:36 am
I need to switch SQL queries when I select an option from a dropdown menu using PHP without using a submit button. How would I do so with javaScript? I have nothing in my <head> to support this so far.
Code: Select all
<div class="main-content">
<h1>Matches
<form method="get">
<select id="match_order" name="match_order">
<option selected="selected" disabled="disabled">Select an Order</option>
<option value="1">Big</option>
<option value="2">Little</option>
<option value="3">Year Matched</option>
</select>
</form>
</h1>
<?php
switch ($match_order) {
case 1:
$match_set = mysql_query('SELECT * FROM matches ORDER BY big ASC', $connection);
break;
case 2:
$match_set = mysql_query('SELECT * FROM matches ORDER BY little ASC', $connection);
break;
case 3:
$match_set = mysql_query('SELECT * FROM matches ORDER BY match_year ASC', $connection);
break;
default:
$match_set = mysql_query('SELECT * FROM matches ORDER BY big ASC', $connection);
break;
}
if (!$match_set) {
die("Database query failed: " . mysql_error());
}
?>