I have a dropdown list, that when changed passes the value to a controller.
This controller, through the model then runs a query that returns multiple results.
I need to somehow populate my dropdown list with the results of the query.
my syntax is:
Controller
function GetDeliveryAddressfromCustomer(){
$this->load->model('Sales_model');
if (isset($_POST['data'])){
$q = strtolower($_POST['data']);
$data = $this->Sales_model->GetDeliveryAddressfromCustomer($q);
$this->output->set_content_type('application/json')->set_output(json_encode($data));
}
}
Model
function GetDeliveryAddressfromCustomer($q){
$this->db->select('deliveryaddress');
$this->db->where('Account', $q);
$query = $this->db->get('Client');
if($query->num_rows > 0){
foreach ($query->result_array() as $row){
$row_set[] = htmlentities(stripslashes($row['deliveryaddress']));
}
return $row_set;
}
}
View JS
$.post('GetDeliveryAddressfromCustomer', {data:selectedObj.value},function(result) {
var selcust = selectedObj.value;
//what to put here to pupulate dropdown list
});
View select
<select id="deliveryaddress" name="deliveryaddress" data-mini="true" data-theme="a">
<option value="0"></option>
</select>
the error is: Trying to get property of non-object
I presume the error is from the multiple results being returned. selectedObj.value is an array not a value.
I am less worried about the part of pupulating the dropdown but if you have advice please provide it.
Thanks, Ryan