我正在使用symfony 1.4和Doctrine。我写的一些酒吧/条的应用程序,我有4个表:如何从symfony 1.4的模板中获得DQL结果?
- 产品
- 订单
- product_order
- 酒吧。
我想要获得所有产品在第一个酒吧(即pubs.id = 1)中订购的时间。这是我得到的,但我只能得到第一个产品(products.id = 1)的总和,我需要它们的总和,在这种情况下,我的db中有两种不同的产品。
ProductOrderTable:
public function ordersGetCount(){
$q = Doctrine_Query::create()
->from('ProductOrder l')
->innerJoin('l.Order p ON l.id_order = p.id')
->select('SUM(l.amount) as units')
->andWhere('p.id_pub = 1')
->groupBy('l.id_product')
->orderBy('p.id');
return $q->execute();
}
这里我的动作类:
$this->resultCount= Doctrine_Core::getTable('productorder')->ordersGetCount();
在这里,我的模板:
for($i=0; $i<2; $i++){
echo "<tr>";
echo "<td>".$resultCount[0]->getUnits()[$i]."</td>";//
echo "<td>1</td>";
echo "<td>1</td>";
echo "</tr>";
}
请需要帮助:)
抱歉,但......你能解释一下你的问题吗? – ilSavo
我想获得每个产品的总和(l.amount)。查询工作我认为,但我不知道如何通过“$ resultCount-> getUnits()” – user2294971