I wonder whether someone may be able to help me please.
I have a MySql database containing several tables. My question revolves around the use of data from three of these, 'userdetails', 'detectors' and 'searchheads'.
What I would like to do is to populate a drop down menu on my HTML form that shows the 'detectors' that are user specific and, in turn, another drop down menu that again is user specific but also only shows the 'searchhead' applicable to the 'detector' selection made in the first drop down menu.
All three tables have a 'userid' field and the tables for the 'detectors' and 'search heads' have a 'detectorid' field.
Could someone perhaps please show me how I would go about setting this up because I must admit I haven't a clue where to start.
Many thanks and regards
Chris.
UPDATED JS CODE
<script type="text/javascript" language="javascript">
$(document).ready(function(){
$.fetch_data = function (what) {
var send = {
"what" : what,
"data" : $("select[name=detectors]").val()
};
$.post ("dropdownmenus.php", send, function(data){
$("select[name=" + what + "]").html(data);
});
};
$.fetch_data ("detectors");
$("select[name=detectors]").live("change", function(){
// reset the searchhead as new data will be implemented
$("select[name=detectorsearchheads]").html("");
$.fetch_data ("detectorsearchhead");
});
});
</script>
UPDATED PHP CODE
<?php
$request = array (
"detector" => @$_POST["detector"],
"detector" => @$_POST["detector"] );
// clean $request.
$build_query = "select * from " . $request["what"] . " "
. "where userid = \"" . $user_id . "\"";
$build_results = mysql_query ($build_query);
$return_results = "";
foreach ($build_results as $index => $data) {
$return_results .= "<option value=\"detector" . $data["id"] . "\">" . $data["text"] .
"</option>"; }
echo $return_results; ?>