2016-04-10 42 views
0

我在蛋糕php 2.6中運行自定義查詢。 但我想類似這種結果列表誰在cakephp運行自定義查詢和檢索結果列表

$ SQL = 「SELECT Visit.id FROM訪問」;

$ result = $ this-> Visit-> query($ sql);

結果是:

陣列 0 =>

array 

    'Visit' => 

    array 

     'id' => string '221403' (length=6) 

1 =>

array 

    'Visit' => 

    array 

     'id' => string '221402' (length=6) 

2 =>

array 

    'Visit' => 

    array 

     'id' => string '221397' (length=6) 

3 =>

array 

    'Visit' => 

    array 

     'id' => string '221394' (length=6) 

4 =>

array 

    'Visit' => 

    array 

     'id' => string '221393' (length=6) 

欲結果來:

陣列 0 =>

'id' => string '221403' (length=6) 

1 = >

'id' => string '221402' (length=6) 

2 =>

'id' => string '221397' (length=6) 

3 =>

'id' => string '221394' (length=6) 

4 =>

'id' => string '221393' (length=6) 

回答

0

爲什麼自定義查詢?

而不是使用自定義查詢,你可以簡單的使用:

$visits = $this->Visit->find('all',array('fields' => array('Visit.id'))); 
$this->set('visits',$visits);