function get random_data($table,$where,$num){
$countcus = db($table)->where($where)->count();
$min = db($table)->where($where)->min('id');
$max = $min+$countcus;
if($countcus < $num){$num = $countcus;}
$i = 1;
$flag = 0;
$ary = array();
while($i<=$num){
$rundnum = rand($min, $max);
if($flag != $rundnum){
if(!in_array($rundnum,$ary)){
$ary[] = $rundnum;
$flag = $rundnum;
}else{
$i--;
}
$i++;
}
}
$where[] = ['id','in',$arr];
$data = db($table)->where($where)->select();
return $data;
}
THINKPHP5.1随机获取数据库几条数据
最新推荐文章于 2022-04-05 20:14:38 发布