Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/265.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/65.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
mysql结果在php输出中平均分布到多个组中_Php_Mysql_Sql - Fatal编程技术网

mysql结果在php输出中平均分布到多个组中

mysql结果在php输出中平均分布到多个组中,php,mysql,sql,Php,Mysql,Sql,我需要在不同的总数中平均分配结果。 每组最多6个,最少4个。 我正在努力使is的规模超过两组运动员。 团队需要尽可能平均分配 示例: $sql = "select pid from Athletes order by RAND()"; $results = mysql_query($sql) or die(mysql_error()); $total = mysql_num_rows($results); 如蒙协助,将不胜感激 谢谢 您如何确定何时需要4组还是6组?(1)order

我需要在不同的总数中平均分配结果。 每组最多6个,最少4个。 我正在努力使is的规模超过两组运动员。 团队需要尽可能平均分配

示例:

$sql     = "select pid from Athletes order by RAND()";
$results = mysql_query($sql) or die(mysql_error());
$total   = mysql_num_rows($results);
如蒙协助,将不胜感激


谢谢

您如何确定何时需要4组还是6组?(1)
orderbyrand()
可以降低性能。如果你想要一个随机的顺序,考虑<代码>从SpReTyOrgs< /Cord>中从运动员顺序中选择PID,RAND()SoRtTyOrm。(2)
mysql\u query
是一个旧的、易变的、不推荐使用的查询。看看迁移到mysqli(在最坏的情况下,它与ext/mysql API非常匹配)。你说最小值是4,然后你把7分为4和3。这是怎么回事。这是一个不推荐使用的接口,将从PHP的未来版本中删除。像and这样的现代替换将使您的数据库代码更容易获得正确的结果。@为什么一个对性能有害,而另一个对性能没有影响?他们做完全相同的事情?
订购依据…
零件是否进行了更多评估?
Total = 7 will have 2 groups with one having 4 and the other with 3.
Total = 17 will have 2 groups of 6 and one of 5.
Total = 25 will be 5 groups of 5.
Total = 26 will have 1 group of 6 and 4 groups of 5.