2021-10-07

【苹果CMS V10】高效率按分类随机输出影片,文章,明星

苹果CMS默认的随机,是不支持按分类随机排序的,平常思路是先找出分类下的所有ID,在这些id中随机抽取,这样效率很低,下面一个是比这效率高很多的方法。

 

【老王已应用】

 

 

 

$model = 'Vod';//模型
$where = ['type_id'=> 1];//查询条件
$sorttp='vod_hits_week';//排序方式
$sort='DESC';//排序方式
$order = "$sorttp $sort";
$start=0;//起始位置
$limit = 3;//随机数量
$field = '*';//返回变量

function h2_get_randvod($model,$where,$order,$limit=10,$start=0,$field='*'){
  $countcus = model($model) -> countData($where);
    if($countcus < $limit){
        $limit = $countcus;
        $page_total = 1;
    }else{
         $page_total = floor($countcus / 10);            
    }
    $min = 1;
  $rundnum = mt_rand($min, $page_total);
    $h2_volist_arr_a =  model($model) -> listData($where,$order,$rundnum,$limit,$start,$field);
  $h2_volist_arr = $h2_volist_arr_a['list'];
  return $h2_volist_arr;
}

 

打赏

好文章,更需要你的鼓励

本文由 氢设计 创作,除注明转载/出处外,均为本站原创,转载前请务必署名

最后编辑时间为:2021-11-23 10:21:01

本文链接:https://www.h2sheji.com/show-61.html