把goods表和order_goods关联的的代码

2016-07-07 15:04 来源:www.chinab4c.com 作者:ecshop专家



把goods表和order_goods关联的的代码如何写,我现在写一个函数

function goods_nums_zs($order_id)
{
$sql = "SELECT SUM(goods_number) " .
"FROM " . $GLOBALS['ecs']->table('order_goods') .
" WHERE order_id = '$order_id'";
return $GLOBALS['db']->getOne($sql);

} 这个是没关联的,如何将goods和order_goods关联实现order_goods中goods_id等于goods_id,而且还要满足此条件的前提下goods查询出来的商品的品牌brand_id<>11

这样写错在哪?
function goods_nums_zs($order_id)
{
$sql = "SELECT SUM(g.goods_number) AS shulian " .
"FROM " . $GLOBALS['ecs']->table('order_goods') . "AS g,".
$GLOBALS['ecs']->table('goods') . " AS o " .
" WHERE g.order_id = '$order_id'".
"AND g.goods_id = o.goods_id".
"AND o.brand_id<>11";

return $GLOBALS['db']->getOne($sql);

}


请赐教,完成了我就放出来共享,这个是什么功能!