我想得到某个产品的商品二级分类名称

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

红色部分是我想得到某个产品的商品二级分类名称,现在知道从这个$sql里能查询出$cat_id,在$sql1需要使用$sql里面的$cat_id,这样写好像不对啊,得不到啊,请问大家,我应该怎么办啊。急!!!求助。


/**
* 获得品牌下的商品
*
* @accessprivate
* @paraminteger$brand_id
* @returnarray
*/
function brand_get_goods($brand_id, $cate, $size, $page, $sort, $order)
{

$cate_where = ($cate > 0) ? 'AND ' . get_children($cate) : '';

/* 获得商品列表 */
$sql = 'SELECT g.goods_id, g.cat_id, g.goods_name, g.market_price, g.shop_price AS org_price, ' .
"IFNULL(mp.user_price, g.shop_price * '$_SESSION[discount]') AS shop_price, g.promote_price, " .
'g.promote_start_date, g.promote_end_date, g.goods_brief, g.goods_thumb , g.goods_img ' .
'FROM ' . $GLOBALS['ecs']->table('goods') . ' AS g ' .
'LEFT JOIN ' . $GLOBALS['ecs']->table('member_price') . ' AS mp ' .
"ON mp.goods_id = g.goods_id AND mp.user_rank = '$_SESSION[user_rank]' " .
"WHERE g.is_on_sale = 1 AND g.is_alone_sale = 1 AND g.is_delete = 0 AND g.brand_id = '$brand_id' $cate_where".
"ORDER BY $sort $order";

$res = $GLOBALS['db']->selectLimit($sql, $size, ($page - 1) * $size);

$arr = array();
while ($row = $GLOBALS['db']->fetchRow($res))
{
if ($row['promote_price'] > 0)
{
$promote_price = bargain_price($row['promote_price'], $row['promote_start_date'], $row['promote_end_date']);
}
else
{
$promote_price = 0;
}

$arr[$row['goods_id']]['goods_id']= $row['goods_id'];
if($GLOBALS['display'] == 'grid')
{
$arr[$row['goods_id']]['goods_name'] = $GLOBALS['_CFG']['goods_name_length'] > 0 ? sub_str($row['goods_name'], $GLOBALS['_CFG']['goods_name_length']) : $row['goods_name'];
}
else
{
$arr[$row['goods_id']]['goods_name'] = $row['goods_name'];
}
$arr[$row['goods_id']]['market_price']= price_format($row['market_price']);


$arr[$row['goods_id']]['shop_price'] = price_format($row['shop_price']);
$arr[$row['goods_id']]['promote_price'] = ($promote_price > 0) ? price_format($promote_price) : '';
$arr[$row['goods_id']]['goods_brief']= $row['goods_brief'];
$arr[$row['goods_id']]['goods_thumb']= get_image_path($row['goods_id'], $row['goods_thumb'], true);
$arr[$row['goods_id']]['goods_img']= get_image_path($row['goods_id'], $row['goods_img']);
$arr[$row['goods_id']]['url']= build_uri('goods', array('gid' => $row['goods_id']), $row['goods_name']);

/****************为了alt中显示商品分类******************/
$sql1 = "SELECT cat_name " . 'FROM ' . $GLOBALS['ecs']->table('category') . " WHERE cat_id='$cat_id'";
$result1 = $GLOBALS['db']->getAll($sql1);
$arr = array();
foreach ($result1 AS $idxx => $roww)
{$goods[$idxx]['catname']= $roww['cat_name'];
}
/****************为了alt中显示商品分类******************/

}
return $arr;
}
红色部分是我想得到某个产品的商品二级分类名称,现在知道从这个$sql里能查询出$cat_id,在$sql1需要使用$sql里面的$cat_id,这样写好像不对啊,得不到啊,请问大家,我应该怎么办啊。急!!!

回答:
传递的参数有问题。...

请问一下2楼,哪个有问题,请指明一下,谢谢了。



$sql1查询出来的东西最后都放到循环中的$row里面去了,所以你要是在$sql2 中用到cat_id的话,必须写$row['cart_id']
另外,把你这段里面的那两行$arr = array();删掉吧,这句话在你这个程序不仅没什么用,反倒是把你之前放入$arr数据里的东西清空了。

另外,你这个function 是在组织一个可返回的数组,你最后返回了$arr,但是,你却把你的cart_name放到了$goods数组中了,你到底是想返回什么?这个地方你得搞清楚,要不然你得不到值的。