0

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

2 Answers 2

1

I'm guessing it's this

$CI->db->select("FileName, GUID, Count(GUID) as guidCount");

foreach ($query->result() as $row) {
    $file_name = $row->guidCount;
}
Sign up to request clarification or add additional context in comments.

Comments

1
    $this->db->select('FileName, GUID, Count(GUID) as guidCount');
    $query = $this->db->get('Files');
    // this will call function once and speed up performance not every time in loop
    $rows = $query->result(); 
    foreach ($rows as $row)
    {
       echo $row->FileName;
       echo $row->GUID;
       echo $row->guidCount;
    }

See more @ https://www.codeigniter.com/userguide2/database/active_record.html

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.