2012-10-16 40 views
0

我使用笨2(最新版本) ...讓我們說我有這個疑問:(笨2)獲得MySQL的函數結果使用活動記錄類

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

我知道我能得到GUID

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

但我怎麼能得到Count(GUID):使用此語法&文件名列?

PS。這是一個簡單的例子來解釋我的問題。我需要知道的是如何用笨的活動記錄

回答

1

我猜測它的這個

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

foreach ($query->result() as $row) { 
    $file_name = $row->guidCount; 
} 
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; 
    } 

見得到組成/ MySQL的函數結果更多@http://ellislab.com/codeigniter/user_guide/database/active_record.html