方法一:(适用于栏目非常多的情况下,效率比较好)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
<?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> <? } ?> |
方法二:(栏目不多的情况下可以使用)
1 2 3 4 5 6 7 8 9 10 |
<?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> <? } ?> |