1

I want to load all my rows of column "name" in my table "districts".

I can already read the first row but not more then that.

My Controller:

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

My 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');
    }

In my Controller I have Zend_Debug::dump($array) and the result is:

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

Only the first row ... How can I can convert the read function so I can load all the rows?

2 Answers 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();

    }

Change fetchRow() to fetchAll(). fetchRow() returns one row object or null, fetchAll() returns a rowset object (array of row objects) or an exception/fatal error.

Sign up to request clarification or add additional context in comments.

Comments

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

change that portion of code to

return $your_database_object->fetchAll($select);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.