我正在使用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
不客氣。乾杯! –