Use the Variable from a SELECT to populate a SQL query
Posted: Tue Feb 25, 2014 6:35 pm
I have a Chained SELECT that pull the Make and then Model of what I'm doing, this works great, I now want to be able to take the variable from the Model SELECT and use it in the SQL statement to run a query to return a value which will then be poplulated into the INPUT field I have.
This is the INPUT on my main Form
My getdata.php
the jQuery
When the variable is inserted into the query nothing is returned,no errors show either
question is where have I gone astray with this so far?
This is the INPUT on my main Form
Code: Select all
<div class="row">
<div class="col-md-4">
<div class="form-group">
<label>Seasonal Efficiency Rating</label>
<input type="text" readonly="readonly" class="form-control" id="saprating" name="saprating">
</div>
</div>
</div>Code: Select all
<?php
include "db.php";
$boilermodel = $_POST["boilermodel"];
$sql = "SELECT SAP2009AnnualEfficiency FROM blr.BoilerModel WHERE BoilerModel = '".$boilermodel."' ";
$res = mysql_query($sql);
while($row = mysql_fetch_assoc($res)) {
$array[] = $row['BoilerMakeModel'];
}
echo json_encode($array);
}
?>Code: Select all
<script type="text/javascript">
$(document).ready(function(){
$("select#boilermodel").change(function(){
var boilermodel = $("select#boilermodel option:selected").attr('value');
$.post("assets/configs/getdata.php", {boilermodel:boilermodel}, function(data){
$("input[name='saprating']").html(data);
});
});
});
</script>question is where have I gone astray with this so far?