Created
November 8, 2015 05:28
-
-
Save forecho/cc1139bcbba5de6e5df1 to your computer and use it in GitHub Desktop.
百万数据库某个表「伪」随机显示 N 条数据思路
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * 随机 | |
| * @param int $rows 数据池 | |
| * @return mixed | |
| */ | |
| protected function random($rows = 100) | |
| { | |
| $count = User::find()->select(['itemid'])->where([])->count(); | |
| $random = mt_rand($rows, $count - $rows); | |
| $model = User::find()->where(['>=', 'id', $random])->joinWith(['type'])->limit($rows)->all(); | |
| shuffle($model); // 洗牌 | |
| return $model; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment