I am using codeigniter in my app. I have an autocomplete drop down that on selection calls a controller function to display further details about the selected dropdown value.
I have used the below syntax successfully to return a single result but now need to return an entire array to the view and display each returned row with multiple columns.
So the syntax for the single result is:
Controller
function get_link_load_options(){
$this->load->model('Sales_model');
if (isset($_POST['data'])){
$q = strtolower($_POST['data']);
$data = $this->Sales_model->get_link_load_options($q);
$this->output->set_content_type('application/json')->set_output(json_encode($data));
}
}
Model
function get_link_load_options($q){
$this->db->select('TotalCubes,CustomerName,TotalCubes, TreatedCubes');
$this->db->where('CustomerOrderID', $q);
$query = $this->db->get('Customer_Order_Summary');
if($query->num_rows > 0){
foreach ($query->result_array() as $row){
$row_set[] = htmlentities(stripslashes($row['TotalCubes']));
return $row_set;
}
}
View Jquery
$.post('get_link_load_options', {data:substr[1]},function(result) {
$('input[name^="totalcubes"]').val(result[0]);
});
So how do I adapt/change this to populate my view with the get_link_load_options function results.
Is this the best method or should I be using another method?
Can the entire array $query be passed and if so how do I use jquery / javascript to render the array into a table?
When I do the above, I get the response:
Message: json_encode(): type is unsupported, encoded as null
Thanks as always.
echo json_encode($data);for ajax in my service, and probably you can pass$queryresult directly to thejson_encodefunction.