开发者

zend_db_table how do i select all distinct values for a specific column

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()

w开发者_高级运维hich 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?


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);
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜