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);
精彩评论