I created the following arrays that hold a vehicle manufacturer and the other the model. I want to have two dropdown boxes that are dependent on each other, so the first you select manufacturer and the second it populates the models based on your first choice. I currently have this working, but it must refresh the page each change of manufacturer. I want these arrays to be sent to a javascript file and then javascript control the two dropdowns. I have checked out javascriptkit.com, but can't seem to get a good understanding of this without hardcoding. Any help would be appreciated.
Thanks!
Here is my PHP code.
// initialize array for make/model
$mfg_array = array();
$model_array = array();
// query all manufacturers
$mfg_result = mysql_query("select * from manufacturer") or die(mysql_error());
// initialize variables to loop through results
$i = 0;
$j = 0;
// loop through manufacturers and store id and name in array
while($mfg_row = mysql_fetch_array($mfg_result)){
$mfg_tmp = array("mfg_id" => $mfg_row["mfg_id"],
"mfg_name" => $mfg_row["mfg_name"]
);
$mfg_array[$i++] = $mfg_tmp;
$mfg_id = $mfg_row["mfg_id"]; // store mfg_id in variable for the next query
// query for models for the current manufacturer
$model_result = mysql_query("Select * from model where mfg_id = '$mfg_id'") or die(mysql_error());
// loop through manufacturers and store id and name in array
while ($model_row = mysql_fetch_array($model_result)){
$model_tmp = array("model_id" => $model_row["model_id"],
"mfg_id" => $model_row["mfg_id"],
"model" => $model_row["model"]
);
$model_array[$j++] = $model_tmp;
}
}