_db->select(); $select->from($this->pair, array('id')); $select->where('`Faq`.`idCategory` = ?', $categoryId, Qs_Db::INT_TYPE); $select->order('Faq.sorter'); return $this->_db->fetchOne($select); } protected function _prepareList(&$list) { parent::_prepareList($list); $result = array(); foreach ($list as $row) { $result[$row['idCategory']][] = $row; } $list = $result; } public function getNotEmptyCategories() { if (null === $this->_notEmptyCategories) { $select = $this->_db->select(); $select->from($this->pairFaqCategory, array('id', 'title')); $select->order('FaqCategory.sorter'); $select->where(new Zend_Db_Expr('(' . $this->_getSelectCountCategoryFaqs() . ') > 0')); $this->_notEmptyCategories = $this->_db->fetchPairs($select); } return $this->_notEmptyCategories; } protected function _getSelectCountCategoryFaqs() { $select = $this->_db->select(); $select->from($this->pair, 'COUNT(*)'); $select->where("`Faq`.`idCategory` = `FaqCategory`.`id`"); return $select; } }