2013-01-22 73 views
1

我想在我的表「區」中加載列「name」的所有行。從列+ zend框架讀取多個行

我已經可以讀取第一行,但不是那麼多。

我的控制器:

public function showdataAction() 
    { 
     $districtMapper = new Backoffice_Model_DistrictMapper(); 
     $array = $districtMapper->read();  
     Zend_Debug::dump($array);  
    } 

我DistrictMapper:

public function read() 
    { 
     $table = $this->_dbTable;  
     $columns = array('wijk' => 'wijk', 'coords' => 'coords',);  
     $select = $table->select() ->from($table, $columns) ->order('wijk ASC'); 
     if ($row = $table->fetchRow($select)) { 
      return $row->toArray(); 
     }  
     throw new Exception('The requested data cannot be found'); 
    } 

在我的控制器我有Zend_Debug ::轉儲($陣列),其結果是:

array(2) { 
    ["wijk"] => string(10) "Binnenstad" 
    ["coords"] => string(2186) "3.72448685517794,51.0601522198842, 
       0 3.72577413282654,51.0597215800093,0 3.72594328459339, 
       51.0600395135711,0 3.72699385985136, 51.060876600363, 
       0 3.72764765694006,51.0608474287073, 
       0 3.7281167878913,51.0605006616679,0 3.72955689560896, 
       51.059999738927" 
} 

只有第一行...我怎樣才能轉換閱讀功能,所以我可以加載所有的行?

回答

1
public function read() 
    { 
     $table = $this->_dbTable;  
     $columns = array('wijk' => 'wijk', 'coords' => 'coords',);  
     $select = $table->select() ->from($table, $columns) ->order('wijk ASC'); 
     //try/catch might make more sense as fetchAll() returns an object or an exception. 
     $result = $table->fetchAll($select) 

     return $result->toArray(); 

    } 

變化fetchRow()fetchAll()那部分。 fetchRow()返回一行對象或null,fetchAll()返回行集對象(行對象數組)或異常/致命錯誤。

0
if ($row = $table->fetchRow($select)) { 
      return $row->toArray(); 
     } 

變化的代碼來

return $your_database_object->fetchAll($select);