开发者

Need Help with Zend_Db_Select

I'm currently working with Zend Framework.

just wondering is there a easy way to make my results in Numeric array format rather then associative array?

Eg Here is my zend_db_select statement

   $select = $this->select()->from('providerReligionPreference','religionTypeId')
           ->where('providerId = ?',$providerId)
           ->where('quoteTypeId = ?',$quoteTy开发者_如何学编程peId);

   $result = $this->fetchAll($select);

   var_dump($result->toArray());

        return $result->toArray();

When I var_dump $result->toArray() I get

array(2) { [0]=> array(1) { ["religionTypeId"]=> string(1) "1" } [1]=> array(1) { ["religionTypeId"]=> string(1) "2" } } 

But I wanted to be in Numeric array format like

$result[0]="1";
$result[1]="2";

Can anybody help me out? Thanks you so much

Cheers


Your $result is a rowset, so you could do something like this:

$numericResult = array();
foreach ($result as $row) {
     $numericResult []=  $row->religionTypeId;
}


$adapter->setFetchMode(Zend_Db::FETCH_NUM);
$select = $adapter->select();
...

or even both

$adapter->setFetchMode(Zend_Db::FETCH_BOTH);


The return of fetchAllis a rowset, like explain in : http://framework.zend.com/manual/fr/zend.db.table.rowset.html

The rowset implement "SeekableIterator" and "Countable" : http://framework.zend.com/apidoc/core/Zend_Db/Table/Zend_Db_Table_Rowset_Abstract.html

Use:

$myAssocArray = array();
foreach ($result as $row) {
    $myAssocArray[] = $row->religionTypeId;
}


$adapter->setFetchMode(Zend_Db::FETCH_NUM);
$result = $this->fetchAll($select);

or

$result = $adapter->fetchAll($select, array(), Zend_Db::FETCH_NUM);

assuming $this is instance of Zend_Db_Table (No one will extend adapter as model, right?):

$result = $this->getAdapter()->fetchAll($select, array(), Zend_Db::FETCH_NUM);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜