$count_number = $db->result($db->query("select count(*) from $table_template_scene"),0);
        $rand_number  = rand(0,$count_number);
        if(($rand_number - 3) < 0 ){
           $rand_number = 0;
}
elseif(($rand_number + 3) > $count_number){
           $rand_number = $rand_number - 3;
}
$sql   =  "select template_id,title,show_logo from $table_template_scene ORDER BY template_id DESC LIMIT $rand_number,3";

解决方案 »

  1.   

    不能使用 ORDER BY RAND()???
    你的是什么版本???CREATE TEMPORARY TABLE tmp select id,rand() as key from tbl_name

    CREATE TABLE tmp select id,rand() as key from tbl_name
    创建含有随机信息的表tmp,不会这个也不能用吧?select a.* form tbl_name a,tmp b where a.id=b.id order b.key limit 0,nnn
      

  2.   

    我些个麻烦的:)
    function rndstr($chars) { $max=count(explode(",",$chars))-1;
    $array=explode(",",$chars);
    mt_srand((double)microtime() * 1000000);
    for($i = 0; $i < $max; $i++) { 
        
         if ($i+1==$max)
    {
         $hash .= $array[mt_rand(0,$max)]; 
        }else{
        $hash .= $array[mt_rand(0,$max)].",";
    }

    $char=$hash;
    $count=count(explode(",",$char))-1;
    $array=explode(",",$char);for ($i=0;$i<$count;$i++)
    {
     $co=0;
      for ($j=0;$j<$count;$j++)
    {
         if ($array[$i]==$array[$j])
    {
     $co=$co+1;
        }
    }

    if ($co<=1)
    {
    if ($i+1==$count){
    $hanstr.=$array[$i];
    }else{
    $hanstr.=$array[$i].",";
    }
        }

    }$hanstr=str_replace(" ",",",trim(str_replace(","," ",$hanstr)));
    return $hanstr;
    }