1

テーブル「districts」の列「name」のすべての行をロードしたいと思います。

私はすでに最初の行を読むことができますが、それ以上は読むことができません。

私のコントローラー:

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::dump($ array)があり、結果は次のようになります。

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"
}

最初の行のみ...すべての行をロードできるように読み取り関数を変換するにはどうすればよいですか?

4

2 に答える 2

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()1つの行オブジェクトまたはnullをfetchAll()返し、行セットオブジェクト(行オブジェクトの配列)または例外/致命的なエラーを返します。

于 2013-01-23T09:59:16.570 に答える
0
if ($row = $table->fetchRow($select)) {
           return $row->toArray();
       }

コードのその部分をに変更します

return $your_database_object->fetchAll($select);
于 2013-01-22T13:18:34.073 に答える