Reputation: 115
I'm running this in CI, and $query->result_array()
is returning null values, however, when I use $this->db->last_query(), and print out the query, then run it in a MySQL client (Sequel Pro), I get values back as I would expect. What would cause this to return NULL when doing it through CI? I've got other queries that look very similar and work just fine, but this one's being fussy.
Here is the code for the query:
public function get_current_eval($pers_id = NULL, $assID = NULL){
$query = $this->db->select('person.last_name, person.rest_of_name, person.id')
->from('person_course_conceptual_assessment AS pcca')
->join('person', 'person.id = pcca.faculty_id')
->where('pcca.assessment_id', $assID)
->get()
->result_array();
return $query;
}
This is what it's returning
Array(
[0] => Array
(
[last_name] =>
[rest_of_name] =>
[id] => 000000000
)
)
Here's what $this->db->last_query() returns:
SELECT person.last_name, person.rest_of_name, person.id
FROM (person_course_conceptual_assessment AS pcca)
JOIN person ON person.id = pcca.faculty_id
WHERE `pcca`.`assessment_id` = '123456'
I copied that straight to the MySQL GUI and pasted it just as a normal query, runs fine, and returns correct values for all 3 params. Any ideas as to what would cause this for this specific instance?
Upvotes: 1
Views: 47
Reputation:
Try some thing like
Check can get $variables like $assID
public function get_current_eval($pers_id, $assID){
$this->db->select('p.last_name, p.rest_of_name, p.id');
$this->db->from($this->db->dbprefix .'person_course_conceptual_assessment pcca', 'left');
$this->db->join($this->db->dbprefix . 'person p', 'p.id = pcca.id', 'left');
$this->db->where('pcca.assessment_id', $assID);
$query = $this->db->get();
if ($query->num_rows() > 0) {
return $query->result_array();
} else {
return false;
}
}
Upvotes: 1