我要劃分學生分組方式,並將它們存儲在數據庫如何劃分學生在SQL
students 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15.....20
例子:Total no.of students 20
讓4名學生每組(1,2,3, 4個1組和第2組5,6,7,8等等.....)
那麼就應該有5組創建
我試圖像這樣在錯誤我是做for循環。
$studentQuery = $conn->query("
select s.student_pid,i.email,s.student_email,s.student_fname,
s.student_lname,s.profile_pic from r_job_invitations i
LEFT JOIN
tbl_students s
ON
i.email = s.student_email
where i.id_job = ".$jobID." and inv_res = 1");
$totalIndividuals = mysqli_num_rows($studentQuery);
$groups = round($totalIndividuals/5,0,PHP_ROUND_HALF_DOWN);
for ($j = 1; $j <= $groups; $j++) {
for ($i = 0; $i <= $totalIndividuals; $i++) {
$GroupsQuery = $conn->query("INSERT INTO
r_test_group (student_id,job_id,group_name)
values ('".$studentResults['student_pid']."',
'".$jobID."','Group'".$j.")");
}
}
有*總是*空格 –
@YourCommonSense - 至少在OP的例子中不存在;) –