如何把首页调用最新评论改为随机评论?

2016-07-07 14:55 来源:www.chinab4c.com 作者: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;
}
}


?>




<!--数据调用-最新评论开始 -->
<?php
$this->assign('my_comments',get_comments(12)); // 数据条数
?>


<!--{foreach from=$my_comments item=comments}-->
<li style="height: 60px; display: list-item;">
<div class="p-img ld">
<a rel="nofollow"href="goods-{$comments.id_value}.html" target="_blank" title="{$comments.goods_name}"><img src="{$comments.goods_thumb}" alt="{$comments.goods_name}" width="50" height="50"><b class="ci cix1"></b></a>
</div>
<div class="p-name"><a rel="nofollow" href="goods-{$comments.id_value}.html" target="_blank" title="{$comments.goods_name}">{$comments.goods_name}</a></div>
<div class="p-detail"><a rel="nofollow" href="goods-{$comments.id_value}.html" target="_blank">{$comments.content}</a>
</div>
</li>
<!--{/foreach}-->

</div>

回答:
order by rand()

其实调用最新的也可以呀 为什么要改呢 招募 友情链接 啊



我也知道使用order by rand()但由于个人并不懂代码,不知道在哪里修改。。。
能不能指点指点?
谢谢

直接在你的语句中ORDER BY a.add_time DESC 这句改掉




哈, 非常感谢!使用你之前说的order by rand() 完美解决了

我也遇到这个问题了....高手出来帮忙解答一下