I am trying to create a search where the user select two different bit of data from databases and it them prints some results that meet requirements. I know I need to use ajax or something similar but I have little idea how I should be doing it. The first drop down box works fine as that doesn't depend on anything here is the code for that.
<select name="raceTrack2" onchange="">
<?php
$postids = $wpdb->get_col("SELECT trackName FROM " . $trackTableName . ";");
foreach ($postids as $value) {
echo '<option>' . $value . '</option>' ;
}
?>
</select>
That works fine now the next step I need to do is where it start to get complicated I need to take the value of the first selection box and add it into the sql query of the next one then run that query when the first selection box changes using onchange.
<select name="raceDate">
<?php
$postids2 = $wpdb->get_col("SELECT DISTINCT raceDate FROM " . $tableName . " WHERE trackName = '" . $track . "';");
foreach ($postids2 as $value2) {
echo $value2 ;
}
?>
</select>
Then I need to take the value of both of these dropdowns and use it in this final query to display the results.
$postids = $wpdb->get_results("SELECT driverName, driverClass, driverPosition FROM " . $tableName . "WHERE trackName = '" . $track . "' AND raceDate = " . $date . ";");
foreach ($postids as $value) {
echo '<tr valign="top">';
echo '<td>' . $value->driverName . '</td>';
echo '<td>' . $value->driverClass . '</td>';
echo '<td>' . $value->driverPosition . '</td>';
echo '</tr>';
}
}
Any help would be appreciated.