Reputation: 88
so I'm having this issue not being able to get just a string from a table. This is my method in the controller:
public function get_tree($id){
$data['tree'] = $this->Product_model->get_tree($id);
return $data;
}
And this is the function in the model:
function get_tree($id){
$this->db->select('ascending_path');
$this->db->from('category');
$this->db->where('id', $id);
$result = $this->db->get();
return $result;
}
I'm showing this with Ajax into the view but nothin seems to show up. There is not even an error, 200 status code and the request is shown in the access log. Any hints?
PS: if I try to json_encode it and then pass the dataType:json in the ajax call all it comes back is:
{"tree":{"conn_id":{"affected_rows":null,"client_info":null,"client_version":null,"connect_errno":null,"connect_error":null,"errno":null,"error":null,"error_list":null,"field_count":null,"host_info":null,"info":null,"insert_id":null,"server_info":null,"server_version":null,"stat":null,"sqlstate":null,"protocol_version":null,"thread_id":null,"warning_count":null},"result_id":{"current_field":null,"field_count":null,"lengths":null,"num_rows":null,"type":null},"result_array":[],"result_object":[],"custom_result_object":[],"current_row":0,"num_rows":null,"row_data":null}}
Everything seems to be null. I don't even know what is that object, I mean, the query is supposed to bring just one string.
Upvotes: 4
Views: 1638
Reputation: 1599
Change return $result;
to return $result->result();
Read more about Generating Query Results here
Upvotes: 2
Reputation: 38584
use this
function get_tree($id){
$query = $this->db->query("SELECT ascending_path FROM category WHERE id ='$id'");
$result = $query->result_array();
return $result;
}
Upvotes: 1