需要 Zend_Db_Select 帮助

发布于 2024-10-22 18:45:30 字数 769 浏览 3 评论 0原文

我目前正在使用 Zend 框架。

只是想知道是否有一种简单的方法可以使我的结果采用数字数组格式而不是关联数组?

例如,这是我的 zend_db_select 语句,

   $select = $this->select()->from('providerReligionPreference','religionTypeId')
           ->where('providerId = ?',$providerId)
           ->where('quoteTypeId = ?',$quoteTypeId);

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

   var_dump($result->toArray());

        return $result->toArray();

当我 var_dump $result->toArray() 时,我得到了

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

但我想采用数字数组格式,例如

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

有人可以帮我吗? 非常感谢你

干杯

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 = ?',$quoteTypeId);

   $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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

葮薆情 2024-10-29 18:45:30

您的 $result 是一个行集,因此您可以执行以下操作:

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

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

$numericResult = array();
foreach ($result as $row) {
     $numericResult []=  $row->religionTypeId;
}
長街聽風 2024-10-29 18:45:30
$adapter->setFetchMode(Zend_Db::FETCH_NUM);
$select = $adapter->select();
...

甚至两者兼而有之

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

or even both

$adapter->setFetchMode(Zend_Db::FETCH_BOTH);
音盲 2024-10-29 18:45:30

fetchAll的返回是一个行集,如解释:http://framework.zend.com/manual/fr/zend.db.table.rowset.html

行集实现“SeekableIterator”和“Countable”: http://framework.zend.com/apidoc/core/Zend_Db/Table/Zend_Db_Table_Rowset_Abstract.html

使用:

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

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;
}
遥远的绿洲 2024-10-29 18:45:30
$adapter->setFetchMode(Zend_Db::FETCH_NUM);
$result = $this->fetchAll($select);

或者

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

假设 $this 是 Zend_Db_Table 的实例(没有人会将适配器扩展为模型,对吧?):

$result = $this->getAdapter()->fetchAll($select, array(), Zend_Db::FETCH_NUM);
$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);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文