2013-08-27 35 views
2

簡單的問題,我卡上:笨活動記錄查詢僅在表中返回的第一項

這裏是我的活動記錄查詢:

public function get_org() 
    { 
    return $this->db 
      ->get('organizations') 
      ->row(); 
    } 

這隻會返回第一行中的DB 。 如果我擺脫->row();它返回奇數位:

object(CI_DB_mysql_result)#17 (8) { 
    ["conn_id"]=> 
    resource(8) of type (mysql link persistent) 
    ["result_id"]=> 
    resource(12) of type (mysql result) 
    ["result_array"]=> 
    array(0) { 
    } 
    ["result_object"]=> 
    array(0) { 
    }  
    ["custom_result_object"]=> 
    array(0) { 
    } 
    ["current_row"]=> 
    int(0) 
    ["num_rows"]=> 
    int(2) 
    ["row_data"]=> 
    NULL 
} 

請告訴我奇怪的是完全相同的查詢工作完全在其他地方我對於不同的表碼。

對此提出建議?

+0

你已經使用了row()函數,所以它返回單行,使用result_array()函數 – PravinS

回答

5

嘗試像

public function get_org() 
{ 
    $query = $this->db->get('organizations'); 

    foreach ($query->result() as $row) 
    { 
     $result_arr[] = $row; 
    } 
    return $result_arr; 
} 

row()將返回只有一行結果數組。

或者你也可以嘗試result_array()作爲@Hashem Qolami說,像

public function get_org() 
{ 
    $result = $this->db->get('organizations'); 
    return $result->result_array(); 
} 
+1

好的電話。我仍然不明白爲什麼它這樣做。我明白'$ row()'做了什麼,但它在別處工作。咩。 – JDillon522

+0

尋找'result_array()'? –

+0

是的,我們也可以用它... – Gautam3164