Search code examples
phpcodeignitercodeigniter-2

(CodeIgniter 2) Get mysql function result using active record class


I'm using CodeIgniter 2 (latest build)...let's say I have this query:

$CI->db->select("FileName, GUID, Count(GUID)");
$query = $CI->db->get('Files');

I know I can get GUID & FileName columns using this syntax:

foreach ($query->result() as $row) {
    $file_name = $row->FileName;
}

But how can I get the Count(GUID)?

PS. This is a simple example to explain my question. All I need to know is how to get the composed / mysql function result using codeigniter active record


Solution

  • I'm guessing it's this

    $CI->db->select("FileName, GUID, Count(GUID) as guidCount");
    
    foreach ($query->result() as $row) {
        $file_name = $row->guidCount;
    }