方法一:(适用于栏目非常多的情况下,效率比较好)
折叠PHP 代码
- <?php
- function IslastClassid(){
- global $class_r;
- foreach ($class_r as $k => $v) {
- if ($v['islast'] == 1) {
- $all[]= $v['classid'];
- }
- }
- $rand_key = array_rand($all , 5);//随机取5个
- foreach ($rand_key as $k => $v) {
- $classall.= $v.',';
- }
- $classall = trim($classall , ',');
- $classall = $classall ? $classall : 0 ;
- return $classall;
- }
- $class_sql=$empire->query('select * from '.$dbtbpre.'enewsclass where classid in ('.IslastClassid().') order by myorder');
- while($class_row=$empire->fetch($class_sql)){
- $classurl=sys_ReturnBqClassUrl($class_r[$class_row['classid']]); //栏目链接地址
- ?>
- <li><a href="<?=$classurl?>"><?=$class_row['classname']?></a></li>
- <?
- }
- ?>
方法二:(栏目不多的情况下可以使用)
折叠PHP 代码
- <?php
- $class_sql=$empire->query('select * from '.$dbtbpre.'enewsclass where islast=1 order by RAND() LIMIT 5');
- while($class_row=$empire->fetch($class_sql)){
- $classurl=sys_ReturnBqClassUrl($class_r[$class_row['classid']]); //栏目链接地址
- ?>
- <li><a href="<?=$classurl?>"><?=$class_row['classname']?></a></li>
- <?
- }
- ?>