2012-10-31 29 views
0

我想從表中選擇一個特定的列,並返回結果作爲一個簡單的數組。我有以下代碼Zend返回爲數組

$select = $this->select(); 
$select = $select->from($this,array('DISTINCT(conversation_id)','conversation_id')) 
       ->where('user_id =?',$user_id); 
return $this->fetchAll($select)->toArray(); 

問題是,返回的結果是2D。所以如果我想得到結果,我必須去$result[0]['conversation_id']。我怎麼才能得到它,所以我只需要鍵入$result[i]

感謝

+0

爲什麼使用數組,爲什麼不使用對象:'$ result-> conversation_id',只是一個想法。 – RockyFord

回答

0

你需要使用的代碼

return $this->fetchRow($select)->toArray(); 
+0

'return $ this-> fetchAll($ select) - > current() - > toArray();'也應該可以。 – RockyFord

0
$select = $this->select(); 
$select = $select->from($this,array('DISTINCT(conversation_id)')) 
       ->where('user_id =?',$user_id); 

$fetchedData = $this->fetchAll($select); 

$dataArray = array(); 
foreach($fetchedData as $data) 
{ 
    $dataArray[] = $data->conversation_id; 
} 
return $dataArray; 

以下行這是你在找什麼?

+0

是的,我認爲沒有這個可能有辦法做到這一點? – user1083320