I have a codeigniter model function which queries a database and sends the result back to the controller, encoded as json.
the entire function is shown below:
function get_skufamily_cube($q){
$sql=("select min([Pieces]) as ProductCode from
(SELECT
[ProductCode]
,[Description]
,[Length]
,[Pieces]
,[Thickness]
,[Width]
,([width]*1000) w2
,([thickness]*1000) t2
,REPLACE((convert(varchar,convert(decimal(8,1),length))),'.','') AS l2
,concat(([width]*1000),([thickness]*1000),REPLACE((convert(varchar,convert(decimal(8,1),length))),'.','')) AS pc
,REPLACE([ProductCode],concat(([width]*1000),([thickness]*1000),REPLACE((convert(varchar,convert(decimal(8,1),length))),'.','')),'') as grade
,CONCAT(([width]*1000),([thickness]*1000),REPLACE([ProductCode],concat(([width]*1000),([thickness]*1000),REPLACE((convert(varchar,convert(decimal(8,1),length))),'.','')),'')) as options
FROM [hammerhead].[dbo].[ProductList]) as p
where Options like '%$q%' ");
$query=$this->db->query($sql);
if($query->num_rows > 0){
foreach ($query->result_array() as $row){
$row_set[] = htmlentities(stripslashes($row['ProductCode']));
echo $row['ProductCode']; // to see database result and troubleshoot
}
$this->output->set_content_type('application/json')->set_output(json_encode($row_set));
}
}
$q is being passed successfully to the query and the output of the query in echo $row['ProductCode']; is consistent with the result I require. in this case it is 108. the database query returns a single result in a single field.
For some reason, this is no tbeing passed back tot he controller correctly.
Controller is:
$this->load->model('Sales_model');
if (isset($_POST['data'])){
$q = strtolower($_POST['data']);
$data = $this->Sales_model->get_skufamily_cube($q);
$this->output->set_content_type('application/json')->set_output(json_encode($data));
}
}
In my developer tools, I can see the server response
108NULL. 108 being my echo and NULL being the json response. if I remove the echo this is simply NULL.

Laslty, I need to populate the input in my table row with the value. my view jquery syntax for this is:
$.post('get_skufamily_cubes', {data:selectedObj.value},function(result)
{
$(this).find('input[id^="cubesperbundle"]').val(result);
});
Currently nothing is populated. the html input name and id is:cubesperbundle but has the row number appended to it hence the 'input[id^="cubesperbundle"]'
Any assistance would be appreciated.
Thanks and Regards,