I am running the following query in codeiginter, I want to return the data from the database but I'm getting a blank array as a response. My attempts to debug this issue have shown that the return value from the model may be the issue. I need a extra pair of eyes on this so if anyone can help me let me know.
Model
function test($term)
{
$sql = "select description from category where title = '$term'";
$query = $this->db->query($sql);
return $query->result();
}
Controller
function test()
{
$this->load->model('test');
$term = $this->input->post('term',TRUE);
$rows = $this->test->test($term);
echo json_encode($rows);
}
your code looks correct... try printing the last query that was made and check it out
COntroller
function test()
{
$this->load->model('test');
$term = $this->input->post('term',TRUE);
$rows = $this->test->test($term);
echo $this->db->last_query();exit; //this gives you the last query that was made.
echo json_encode($rows);
}
check if the posted value is correct... you can even try running this in mysql and see if this is returning any rows...