So I am trying to find a way to have a random name selected based on information from a table.
Users Table:
UserID | Name | Class |
---|---|---|
KLM99 | Kim Lowe | Maths1 |
JPM17 | Jasper Pepper | Science2 |
TES1 | Tester 1 | Science2 |
TES2 | Tester 2 | Science2 |
TES3 | Tester 3 | Science2 |
TES4 | Tester 4 | Science2 |
Assignment Table
AssignmentID | Class | AssignmentName |
---|---|---|
1 | Maths1 | MathsAssignment1 |
2 | Science2 | ScienceAssignment1 |
3 | Science2 | ScienceAssignment2 |
Maker Table
MarkerID | AssignmentID | User | Marker1 | Marker2 |
---|---|---|---|---|
1 | 2 | JPM17 | ||
2 | 2 | TES1 | ||
3 | 2 | TES2 | ||
4 | 2 | TES3 | ||
5 | 2 | TES4 |
I want to get a list of all the students in that are in a class (Science2) and randomly select 2 students to mark each others work. Students can only mark 2 other students work.
E.g JPM17 should mark TES1 and TES2. TES1 should mark JPM17 and TES2
All the tables have been created and data is inputed in. I'm just having difficulty with the PHP randomizing it to ensure a student doesn't mark more than 2 students work or doesn't mark their own work.
Code: <?php
$students = array();
// $getModuleID = "SELECT ModuleID FROM ModuleSelected WHERE UserID = '$UserID'"; ------ AND UserID<>'$UserID'
$getModuleID1 = "SELECT
UserID
FROM
ModuleSelected
WHERE ModuleID='$m'
ORDER BY RAND()";
$ModuleIDquery1=mysqli_query($con, $getModuleID1);
$count =1;
foreach($ModuleIDquery1 as $row1) {
$UserID = $row['UserID'];
echo "<tr>";
echo "<td>".$count."</td>";
echo "<td> test </td>";
echo "<td>".$row1['UserID']."</td>";
echo "</tr>";
array_push($students, $row1['UserID']);
$count++;
}
foreach($students as $key => $value){
echo "$value<br>";
}
$my_array = $students;
shuffle($my_array);
foreach($my_array as $key => $value2){
echo "<br>$value2<br>";
}
?>
Using the sufflearray it would randomize the array but it only does it once. Is there a way to get two randomized names and then remove them 2 from the list?
I have a sql table to store the randomized markers.
I am open to better suggestions of randomizing my data if there is a different function in PHP available.