求助:商品搜索的范围中加上商品品牌

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

求助:
在搜索商品的时候,可是实现品牌搜索的功能。即在搜索框中输入品牌可以搜索出该品牌底下的商品。也就是可以搜索商品品牌这个属性。

回答:
你可以在添加商品的时候在关键字里添加改品牌名字 ,这个搜索的时候就可以搜到了

恩 好的 谢谢 因为加了好多商品所以不想再一个一个的加上去我改了一下程序 实现了
$keywords.= "(goods_name LIKE '%$val%' OR goods_sn LIKE '%$val%' OR brand_name LIKE '%$val%' OR keywords LIKE '%$val%' $sc_dsad)";


/* 获得符合条件的商品总数 */
$sql= "SELECT COUNT(*) FROM " .$basic->table('goods'). " AS g ".
"LEFT JOIN " . $GLOBALS['basic']->table('brand') . " AS p ".
"ON p.brand_id = g.brand_id ".
"WHERE g.is_delete = 0 AND g.is_on_sale = 1 AND g.is_alone_sale = 1 $attr_in ".
"AND (( 1 " . $categories . $keywords . $brand . $min_price . $max_price . $intro . $outstock ." ) ".$tag_where." )";





/* 查询商品 */
$sql = "SELECT g.goods_id, g.goods_name, g.market_price, g.is_new, g.is_best, g.is_hot, 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_thumb, g.goods_img, g.goods_brief, g.goods_type ".
"FROM " .$basic->table('goods'). " AS g ".
"LEFT JOIN " . $GLOBALS['basic']->table('member_price') . " AS mp ".
"ON mp.goods_id = g.goods_id AND mp.user_rank = '$_SESSION[user_rank]' ".
"LEFT JOIN " . $GLOBALS['basic']->table('brand') . " AS p ".
"ON p.brand_id = g.brand_id ".
"WHERE g.is_delete = 0 AND g.is_on_sale = 1 AND g.is_alone_sale = 1 $attr_in ".
"AND (( 1 " . $categories . $keywords . $brand . $min_price . $max_price . $intro . $outstock . " ) ".$tag_where." ) " .
"ORDER BY $sort $order";

很强啊。。。

楼主这个是哪个文件修改的啊

帮顶呵呵

谁知道这是修改的那个文件呢

search.php 文件里面修改



$keywords.= "(goods_name LIKE '%$val%' OR goods_sn LIKE '%$val%' OR keywords LIKE '%$val%' $sc_dsad)";
替换为
$keywords.= "(goods_name LIKE '%$val%' OR goods_sn LIKE '%$val%' OR brand_name LIKE '%$val%' OR keywords LIKE '%$val%' $sc_dsad)";

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

$max_page = ($count> 0) ? ceil($count / $size) : 1;
if ($page > $max_page)
{
$page = $max_page;
}

/* 查询商品 */
$sql = "SELECT g.goods_id, g.goods_name, g.market_price, g.is_new, g.is_best, g.is_hot, 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_thumb, g.goods_img, g.goods_brief, g.goods_type ".
"FROM " .$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_delete = 0 AND g.is_on_sale = 1 AND g.is_alone_sale = 1 $attr_in ".
"AND (( 1 " . $categories . $keywords . $brand . $min_price . $max_price . $intro . $outstock . " ) ".$tag_where." ) " .
"ORDER BY $sort $order";
-------------
替换为
---------------
/* 获得符合条件的商品总数 */
$sql= "SELECT COUNT(*) FROM " .$basic->table('goods'). " AS g ".
"LEFT JOIN " . $GLOBALS['basic']->table('brand') . " AS p ".
"ON p.brand_id = g.brand_id ".
"WHERE g.is_delete = 0 AND g.is_on_sale = 1 AND g.is_alone_sale = 1 $attr_in ".
"AND (( 1 " . $categories . $keywords . $brand . $min_price . $max_price . $intro . $outstock ." ) ".$tag_where." )";





/* 查询商品 */
$sql = "SELECT g.goods_id, g.goods_name, g.market_price, g.is_new, g.is_best, g.is_hot, 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_thumb, g.goods_img, g.goods_brief, g.goods_type ".
"FROM " .$basic->table('goods'). " AS g ".
"LEFT JOIN " . $GLOBALS['basic']->table('member_price') . " AS mp ".
"ON mp.goods_id = g.goods_id AND mp.user_rank = '$_SESSION[user_rank]' ".
"LEFT JOIN " . $GLOBALS['basic']->table('brand') . " AS p ".
"ON p.brand_id = g.brand_id ".
"WHERE g.is_delete = 0 AND g.is_on_sale = 1 AND g.is_alone_sale = 1 $attr_in ".
"AND (( 1 " . $categories . $keywords . $brand . $min_price . $max_price . $intro . $outstock . " ) ".$tag_where." ) " .
"ORDER BY $sort $order";
-----------
可惜出错了。。。。

Fatal error: Call to a member function table() on a non-object in F:\usr\LocalUser\hgc15078\search.php on line 366

不错啊。懂程序的改一下就行啊。

关键是我不会 我只会拿来用哦

呵呵 谁知道怎么改哈

好像不可以吧

顶起来,楼主的方法好像不对哦

搞了一下 显示错误 囧