通过order by rand()随机调用慢,尤其是在上万条数据的时候,考虑到效率,没办法只能自己想解决方法.
具体实现过程:
<ul> <?php $sql=$empire->query("select id from {$dbtbpre}ecms_news where classid=7 order by newstime desc limit 100"); while($r=$empire->fetch($sql)) { $aid[]=$r['id']; } //打乱数组 shuffle($aid); $aid=array_slice($aid,1,11); $fid=implode(',', $aid); ?> [e:loop={7,6,0,1,"id in ($fid)",'newstime DESC'}] <li><span><a href="<?=$bqsr['titleurl']?>" target="_self"><img alt="<?=$bqr['title']?>" src="[!--news.url--]skin/want/images/jz.gif" class="lazy" data-original="<?=sys_ResizeImg($bqr['titlepic'],196,110,1,'')?>" /></a><b class="s_g"></b></span> <p><a href="<?=$bqsr['titleurl']?>" target="_self"><?=$bqr['title']?></a></p> </li> [/e:loop] </ul>
如果本文对你有帮助,欢迎打赏本站