ecshop首页调用随机评论

2015-03-11 23:32 来源:www.chinab4c.com 作者:ecshop专家

    目前我通过对ecshop二次开发,解决了ecshop首页评论调用的问题,但是我想希望ecshop首页评论能够随机调用,请问如何实现ecshop评论随机调用呢。目前我的ecshop代码是这样的。

    以下是我目前调用最新评论的库文件,求解如何修改为随机评论?  有没有大牛帮忙解决下? 谢谢
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<div class="globalModule" id="brandList">
<?php


if(!function_exists("get_comments")){
function get_comments($num)
{
$sql = 'SELECT a.*,b.goods_id,b.goods_thumb,b.goods_name FROM '. $GLOBALS['ecs']->table('comment') .
' AS a,'. $GLOBALS['ecs']->table('goods') .'AS b WHERE a.status = 1 AND a.parent_id = 0 and a.comment_type=0 and a.id_value=b.goods_id '.
' ORDER BY a.add_time DESC';
if ($num > 0)
{
$sql .= ' LIMIT ' . $num;
}
//echo $sql;

$res = $GLOBALS['db']->getAll($sql);
$comments = array();
foreach ($res AS $idx => $row)
{


$comments[$idx]['add_time'] = local_date($GLOBALS['_CFG']['time_format'], $row['add_time']);
$comments[$idx]['content'] = $row['content'];
$comments[$idx]['id_value'] = $row['id_value'];
$comments[$idx]['goods_thumb'] = get_image_path($row['goods_id'], $row['goods_thumb'], true);
$comments[$idx]['goods_name'] = $row['goods_name'];
}
return $comments;
}
}


?>

回答:这个问题很容易,很简单。只要修改 ecshop函数的sql按照随即排序就OK了。具体如下。$sql = 'SELECT a.*,b.goods_id,b.goods_thumb,b.goods_name FROM '. $GLOBALS['ecs']->table('comment') .
' AS a,'. $GLOBALS['ecs']->table('goods') .'AS b WHERE a.status = 1 AND a.parent_id = 0 and a.comment_type=0 and a.id_value=b.goods_id '.
' ORDER BY rand()';

 来源:http://www.chinab4c.com