我正在使用zend。我在主页中实施了特色产品。现在我想在每个产品下展示评论。对于所有产品可能提供或不提供评论。我需要使用查询来获取具有评论等级且没有评论等级的产品。如何在这里使用JOIN查询?
下面是我的代码,
public function funFutureProduct($option = array())
{
$start = isset($option['start']) ? $option['start'] : 0;
$limit = isset($option['limit']) ? $option['limit'] : Zend_Registry::get("featured_prod_row_length");
$oDb=Zend_Registry::get("db");
$list_select = $oDb->select()
->from(array('p'=>'product'), array('p.*'))
->join(array('m'=>'manufacturers'),'p.manufacturer_id = m.manufacturer_id', array("manufacture_name"=>'m.name'))
->join(array('s'=>'category'),'s.category_id = p.category_id', array("sub_category_name"=>'s.name'))
->join(array('c'=>'category'),'c.category_id = s.parent', array("category_name"=>'c.name'))
->join(array('p_w'=>'prod_warehouse'),'p_w.product_id = p.product_id', array("curent_stock"=>'p_w.curent_stock'))
->join(array('r'=>'review'),'p.product_id = r.product_id and r.status = 1', array("avg_review_rating"=>new Zend_Db_Expr('AVG(r.rating)'),"count_user_rating"=>new Zend_Db_Expr('COUNT(r.product_id)')))
->limit($limit, $start);
$list_select->where('s.status = 1 AND c.status = 1 AND p.status = 1 AND m.status = 1 AND p.product_id != "" AND p_w.status > 0');
$list_select->group('p.product_id');
$list_select->where('p.featured_product = 1');
$aData=$oDb->fetchall($list_select);
return $aData;
}
当我执行上面,只取其中有回顾率的产品,我也想要得到它没有审查该产品的额定?
请帮助我。
谢谢,我应该使用左连接。我在想什么..... – mymotherland
不客气。干杯! –