1

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?

Napoleon
  • 879
  • 2
  • 14
  • 36

1 Answers1

2

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);
ngsiolei
  • 614
  • 3
  • 5
  • thanks for this mate, it worked. i am wondering though isn't getDbTable supposed to fetch the table name? if so why do i need to add that in the from part again. anyway thanks a lot. – Napoleon Dec 17 '10 at 11:00