zend_db_table 我如何选择特定列的所有不同值

发布于 2024-10-07 13:49:07 字数 330 浏览 2 评论 0原文

大家好,我相信这可能是微不足道的,但我有以下代码

        $response = $groupsmapper->getDbTable()->fetchAll(
        $groupsmapper->getDbTable()->select('group_area_residence')
            ->distinct()

,应该可以让我获得所有不同的 group_area_residence 。但是它会获取该组的所有列。

顺便说一句,我正在使用 zend_db_table 。我该如何解决这个问题?

Hi guys i believe this could turn out to be trivial but i have the following code

        $response = $groupsmapper->getDbTable()->fetchAll(
        $groupsmapper->getDbTable()->select('group_area_residence')
            ->distinct()

which is supposed to get me all the distinct group_area_residence. However it fetches all the columns for the group.

I am using zend_db_table btw. How do i fix this?

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

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

发布评论

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

评论(1

以为你会在 2024-10-14 13:49:07

根据 Zend/Db/Table/Abstract.php 中的 select() ,它检查是否包含 from 部分,而不是获取字段名称

 /**  
 * Returns an instance of a Zend_Db_Table_Select object.
 *
 * @param bool $withFromPart Whether or not to include the from part of the select based on the table
 * @return Zend_Db_Table_Select
 */
public function select($withFromPart = self::SELECT_WITHOUT_FROM_PART)
{    
    require_once 'Zend/Db/Table/Select.php';
    $select = new Zend_Db_Table_Select($this);
    if ($withFromPart == self::SELECT_WITH_FROM_PART) {
        $select->from($this->info(self::NAME), Zend_Db_Table_Select::SQL_WILDCARD, $this->info(self::SCHEMA));
    }    
    return $select;
}

看看下面的代码片段是否有帮助(将 table_name 替换为所需的)

$select = $groupsmapper->getDbTable()
                       ->select()
                       ->distinct()
                       ->from(array('table_name'), array('group_area_residence'));

$response = $groupsmapper->getDbTable()->fetchAll($select);

According to select() in Zend/Db/Table/Abstract.php, it checks whether to include the from part, instead of getting the field name

 /**  
 * Returns an instance of a Zend_Db_Table_Select object.
 *
 * @param bool $withFromPart Whether or not to include the from part of the select based on the table
 * @return Zend_Db_Table_Select
 */
public function select($withFromPart = self::SELECT_WITHOUT_FROM_PART)
{    
    require_once 'Zend/Db/Table/Select.php';
    $select = new Zend_Db_Table_Select($this);
    if ($withFromPart == self::SELECT_WITH_FROM_PART) {
        $select->from($this->info(self::NAME), Zend_Db_Table_Select::SQL_WILDCARD, $this->info(self::SCHEMA));
    }    
    return $select;
}

See if the below code snippet helps (replacing table_name by desired one)

$select = $groupsmapper->getDbTable()
                       ->select()
                       ->distinct()
                       ->from(array('table_name'), array('group_area_residence'));

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