ecshop换模板问题,打印只是显示一个二级分类的商品,求解决方法,$parent_id:一级分类$cat_id :二级分

functionget_category_good($parent_id){$sql='SELECTcat_idFROM'.$GLOBALS['ecs']->table(... function get_category_good($parent_id)
{
$sql = 'SELECT cat_id FROM ' . $GLOBALS['ecs']->table('category') . " WHERE parent_id = '$parent_id '";
$cat_id = $GLOBALS['db']->getall($sql);
$res=array();
foreach($cat_id as $id)
{
$sql='select * from'.$GLOBALS['ecs']->table('goods')."WHERE cat_id='$id[cat_id]'";

$res=$GLOBALS['db']->getall($sql);
foreach($res as $row){
$arr[$row['goods_id']]['goods_id'] = $row['goods_id'];
$arr[$row['goods_id']]['goods_name'] = $row['goods_name'];
$arr[$row['goods_id']]['short_name'] = $GLOBALS['_CFG']['goods_name_length'] > 0 ?
sub_str($row['goods_name'], $GLOBALS['_CFG']['goods_name_length']) : $row['goods_name'];
$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']]['market_price'] = price_format($row['market_price']);
$arr[$row['goods_id']]['shop_price'] = price_format($row['shop_price']);
$arr[$row['goods_id']]['url'] = build_uri('goods', array('gid'=>$row['goods_id']), $row['goods_name']);
}
return $arr;
}
return $res;
}
展开
 我来答
匿名用户
2012-03-23
展开全部
这个写法有两个地方需要改进:
function get_category_good($parent_id)
{
$con = " AND (" . $parent_id . " OR " . get_extension_goods($parent_id) .")";
$sql = 'SELECT g.goods_id, g.goods_name, g.goods_name_style, g.market_price, g.shop_price AS org_price, g.promote_price, ' .
"IFNULL(mp.user_price, g.shop_price * '$_SESSION[discount]') AS shop_price, ".
'g.promote_start_date, g.promote_end_date, g.goods_brief, g.goods_thumb, g.goods_img, b.brand_name ' .
'FROM ' . $GLOBALS['ecs']->table('goods') . ' AS g ' .
'LEFT JOIN ' . $GLOBALS['ecs']->table('brand') . ' AS b ON b.brand_id = g.brand_id ' .
"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 ' . $con ;
$res=$GLOBALS['db']->getall($sql);
foreach($res as $row)
{
$arr[$row['goods_id']]['goods_id'] = $row['goods_id'];
$arr[$row['goods_id']]['goods_name'] = $row['goods_name'];
$arr[$row['goods_id']]['short_name'] = $GLOBALS['_CFG']['goods_name_length'] > 0 ?
sub_str($row['goods_name'], $GLOBALS['_CFG']['goods_name_length']) : $row['goods_name'];
$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']]['market_price'] = price_format($row['market_price']);
$arr[$row['goods_id']]['shop_price'] = price_format($row['shop_price']);
$arr[$row['goods_id']]['url'] = build_uri('goods', array('gid'=>$row['goods_id']), $row['goods_name']);
}
return $arr;
}

一、由某分类查找子分类应用get_extension_goods这个ecshop自带的方法

二、取商品信息里最好避免用select * 这种查所有字段信信息的方法

三、建议此函数加上取的记录条数限制
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式