2013-05-28 93 views
0

我在CakePHP的查詢如下:如何閱讀查詢結果

lnguserID = 10; 
$result = $this->Mymodel->find('all', array(
       'fields' => array('Mymodel.intPhoneID'), 
       'conditions' => array('Mymodel.intUserid'=> $lnguserID) 
      )); 

當我調試的結果是這樣的:echo debug($result);

我得到:

array(
    (int) 0 => array(
     'Mymodel' => array(
      'intPhoneID' => (int) 3975 
     ) 
    ) 
) 

哪有我從結果數組中直接訪問這個id3975?類似於:

result['Mymodel']['intPhoneID']; 

我想在其他查詢中使用它。

+0

hhhhh,嗨,工作感謝。 – OussamaLord

+2

如果它幫助請[接受我的答案](http://meta.stackexchange.com/questions/16721/how-does-accept-rate-work/65088#65088) – Kuf

回答

0
echo $result[0]['Mymodel']['intPhoneID']; 

另外 - 你不需要echo一個調試。這只是:

debug($result[0]['Mymodel']['intPhoneID']); 

我想這是在Controller - 如果是這樣,然後你可以通過「'set'ing」訪問它在查看它:

// Controller 
$this->set('result', $result); 

// View 
debug($result); 
0

,如果這是你的對象:

array(
    (int) 0 => array(
     'Mymodel' => array(
      'intPhoneID' => (int) 3975 
     ) 
    ) 
) 

你需要0訪問數組 - >基於myModel - > intPhoneID,所以使用:

result[0]['Mymodel']['intPhoneID'];