Zend_Db problème group by et count
Bonjour,
J'ai un petit souci pour crée une requête qui est la suivante :
Code:
select *,count(*) as count from offres o, produits p where o.id_produit=p.id_produit group by o.id_produit
Ma base de données :
Code:
1 2 3 4 5 6 7 8 9 10
| Table Offres
id_offre id_produit nom_offre
1 1 ....
2 1 ....
3 2 ....
4 2 ....
Table Produits
id_produit designation_produit
1 .....
2 ..... |
et ma classe ProduitMapper :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
| <?php
class Application_Model_ProduitMapper
{
protected $_dbTable;
public function setDbTable($dbTable)
{
if (is_string($dbTable)) {
$dbTable = new $dbTable();
}
if (!$dbTable instanceof Zend_Db_Table_Abstract) {
throw new Exception('Invalid table data gateway provided');
}
$this->_dbTable = $dbTable;
return $this;
}
public function getDbTable()
{
if (null === $this->_dbTable) {
$this->setDbTable('Application_Model_DbTable_Produit');
}
return $this->_dbTable;
}
public function getOffreCatalogue($id) {
$table = $this->getDbTable();
$select =$table->select(Zend_Db_Table::SELECT_WITH_FROM_PART);
$select->setIntegrityCheck(false);
$select->from($table,array('count' => 'COUNT(offres.id_offre)'));
$select->where('produits.id_catalogue = ? ', $id);
$select->join('offres', 'offres.id_produit = produits.id_produit');
$select->group('offres.id_produit');
$rowset = $this->getDbTable()->fetchAll($select);
return $rowset;
}
} |
Mais dans le résultat la valeur de count est 4 alors qu'elle doit être égale à 2
Une idée ?
Merci pour vos réponses