属性关联商品随机调用

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

在商品详情页里面,属性关联商品是固定的那几个,没有变化,这样不利于搜索引擎抓取。想让这个属性关联商品随机显示,应该修改哪里?(注意是属性关联商品,不是相关商品)
如果用ORDER BY rand()来实现,应该怎样加?
在:
$sql = "SELECT ga.goods_attr_id, ga.attr_value
FROM " .$GLOBALS['ecs']->table('goods_attr'). " AS ga, " .$GLOBALS['ecs']->table('attribute'). " AS a
WHERE a.attr_id = ga.attr_id
AND a.attr_type = 1
AND " . db_create_in($goods_id_array, 'goods_id');
$result_goods_attr = $GLOBALS['db']->getAll($sql);

$_goods_attr = array();
foreach ($result_goods_attr as $value)
{
$_goods_attr[$value['goods_attr_id']] = $value['attr_value'];
}

回答:
$sql = "SELECT ga.goods_attr_id, ga.attr_value
FROM " .$GLOBALS['ecs']->table('goods_attr'). " AS ga, " .$GLOBALS['ecs']->table('attribute'). " AS a
WHERE a.attr_id = ga.attr_id
AND a.attr_type = 1
AND " . db_create_in($goods_id_array, 'goods_id')." order by rand() limit 4";

" . db_create_in($goods_id_array, 'goods_id');
这里改一下, $goods_id_array 数组随机出几个商品, 再 " . db_create_in($goods_rand_array, 'goods_id');

这效率也比用 order byrand()高许多

嗯 楼上的改法不错

老大些,能不能将上面的解决方法改成代码啊?不懂怎么修改啊~拜托了~~~

这个留个记号,hoho

留个记号,坐等更好的办法!

求解决!

求真相]














_______________________________________________________________
http://www.jialigou.com

参考2楼,4楼的方法应可以解决你的问题