function getRandTable($nums, $tables, array $where = null)
{
$num = $nums; //需要抽取的默认条数
$table = $tables; //需要抽取的数据表
$pk = $this->app->db->name("$table")->getPk();
$countcus = $this->app->db->name("$table")->where($where)->field($pk)->select();
$con = '';
foreach ($countcus as $v => $val) {
$con .= $val[$pk] . '|';
}
$array = explode("|", $con);
$data = [];
foreach ($array as $v) {
if (!empty($v)) {
$data[$v] = $v;
};
}
$a = array_rand($data, $num);
// $list = Db::name("$table")->where($pk, 'in', $a,'and','state','==',1)->select();
$list = $this->app->db->name("$table")->where($pk, 'in', $a)->select()->toArray();
return $list;
}
tp5.1 mysql随机获取几条数据
最新推荐文章于 2023-07-23 13:59:06 发布