核心开发看看我改的代码错在哪里了?

2016-07-07 16:43 来源:www.chinab4c.com 作者:ecshop专家

想在商品列表里加上品牌字段,根据luhengqi ( Xeon[祺]) 的提示,修改了lib_goodscat.php文件,品牌已经可以在首页的商品列表显示,但在分类商品显示就失效了,admin提示需要修改category.php,于是修改如下:

$sql = "SELECT g.goods_id, g.goods_name, g.market_price, g.shop_price, g.promote_price, g.promote_start, ".
"g.promote_end, g.goods_brief, g.goods_thumb, b.brand_name ".
"FROM " .$ecs->table('goods'). " AS g ".
"LEFT JOIN ".$ecs->table('brand'). " AS b ON b.brand_id=g.brand_id ".
"WHERE (g.is_on_sale=1) AND (g.is_gift=1 OR g.is_alone_sale=1) AND g.is_delete=0 ";
"ORDER BY $sort $order";
$res = $db->SelectLimit($sql, $size, ($page-1) * $size);
$arr = array();

if ($res)
{
while ($row = $res->FetchRow())
{
$promote_price = bargain_price($row['promote_price'], $row['promote_start'], $row['promote_end']);

$arr[$row['goods_id']]['goods_id']= $row['goods_id'];
$arr[$row['goods_id']]['goods_name'] = $row['goods_name'];
$arr[$row['brand_name']]['brand_name']= $row['brand_name'];$arr[$row['goods_id']]['market_price']= price_format($row['market_price']);
$arr[$row['goods_id']]['shop_price'] = goods_price($row['goods_id'], $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']= empty($row['goods_thumb']) ? 'images/no_picture.gif' : $row['goods_thumb'];
$arr[$row['goods_id']]['url']= build_url('goods', $row['goods_id'], $row['goods_name']);
}
}

其中红字部分是另加的,结果显示如附件效果,品牌显示出的,没有其选项和图片,有图和其他项的显示不出,求解:

12.gif (16.16 KB)

修改后品牌显示问题

12.gif


回答:
上面代码中红色标识的第二部分应该这样写
  1. $arr[$row['goods_id']]['brand_name'] = $row['brand_name'];
复制代码

核心就是核心

这个问题解决了,本想依葫芦画瓢,把search.php也改改,但怎么也不成功,请看看问题出在哪里?红字为增加的代码:

/* 有属性检索的处理 */
if($i> 0)
{
/* 获得符合条件的商品总数 */
$sql = "SELECT COUNT(DISTINCT (g.goods_id)) FROM " .$ecs->table('goods'). " AS g ". $attr_table .
"WHERE g.is_delete=0 AND (g.is_alone_sale=1 OR g.is_gift=0) ".
" AND (( 1 " . $categories . $keywords . $brand . $min_price . $max_price . $intro ." )".$tag_where." )" . $attr_where ;
$count= $db->GetOne($sql);

/* 查询商品 */
$sql = "SELECT DISTINCT g.goods_id, g.goods_name, g.market_price, g.shop_price, g.promote_price, ".
"g.promote_start, g.promote_end, g.goods_thumb, g.goods_brief , b.brand_name ".
"FROM " .$ecs->table('goods'). " AS g ".$attr_table .
"LEFT JOIN ".$ecs->table('brand'). " AS b ON b.brand_id=g.brand_id ".
"WHERE g.is_delete=0 AND (g.is_alone_sale=1 OR g.is_gift=0) ".
" AND (( 1 " . $categories . $keywords . $brand . $min_price . $max_price . $intro ." )".$tag_where." )" .$attr_where .
" ORDER BY $sort $order";

}
else
{

/* 获得符合条件的商品总数 */
$sql = "SELECT COUNT(*) FROM " .$ecs->table('goods'). " AS g ".
"WHERE g.is_delete=0 AND (g.is_alone_sale=1 OR g.is_gift=0) ".
" AND ( 1 " . $categories . $keywords . $brand . $min_price . $max_price . $intro ." )".$tag_where ;
$count= $db->GetOne($sql);

/* 查询商品 */
$sql = "SELECT g.goods_id, g.goods_name, g.market_price, g.shop_price, g.promote_price, ".
"g.promote_start, g.promote_end, g.goods_thumb, g.goods_brief , b.brand_name ". "FROM " .$ecs->table('goods'). " AS g ".
"LEFT JOIN ".$ecs->table('brand'). " AS b ON b.brand_id=g.brand_id ".
"WHERE g.is_delete=0 AND (g.is_alone_sale=1 OR g.is_gift=0) ".
" AND ( 1 " . $categories . $keywords . $brand . $min_price . $max_price . $intro ." ) ".$tag_where.
" ORDER BY $sort $order";
}


$res = $db->SelectLimit($sql, $size, ($page-1) * $size);

$arr = array();
while ($row = $res->FetchRow())
{
$promote_price = bargain_price($row['promote_price'], $row['promote_start'], $row['promote_end']);

$arr[$row['goods_id']]['goods_id']= $row['goods_id'];
$arr[$row['goods_id']]['goods_name'] = $row['goods_name'];
$arr[$row['goods_id']]['brand_name'] = $row['brand_name'];
$arr[$row['goods_id']]['market_price']= price_format($row['market_price']);
$arr[$row['goods_id']]['shop_price'] = goods_price($row['goods_id'], $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']= empty($row['goods_thumb']) ? 'images/no_picture.gif' : $row['goods_thumb'];
$arr[$row['goods_id']]['url']= build_url('goods', $row['goods_id'], $row['goods_name']);