Hi,
I have a problem to develop the logical using php for rotational schedule. I am forwarding the table structure(Output) for your perusal. Please help me to clear the problem ASAP.
rotation 1 rotation 2 rotation 3
-------------------------------------------------------------
module1 Student5 Student1 Student 2
Student6 Student4 Student3
-------------------------------------------------------------
module2 Student2 Student6 Student5
Student4 Student 3 Student1
----------------------------------------------------------------
module3 Student1 Student5 Student4
Student3 Student2 Student6
------------------------------------------------------------
Here, rotation 1,2and 3 will come in column heading. Module1,2 and 3 come as row heading which contains pair of students depends upon each module,rotation(example as student5 and 6 in module1(rowspan = "2").
Student1 to student6 is act as students attending the practical lab(act as rotations) according to subject(act as modules).
Remember, Not to come again for the same student name in same module according to rotation.
Pair of students also not to come again to any modules.
need logical code for rotational schedule
Moderator: General Moderators
-
vijayalakshmi
- Forum Newbie
- Posts: 8
- Joined: Tue Jan 21, 2014 10:22 pm
Re: need logical code for rotational schedule
So show us what you've written so far and where you're getting stuck.
-
vijayalakshmi
- Forum Newbie
- Posts: 8
- Joined: Tue Jan 21, 2014 10:22 pm
Re: need logical code for rotational schedule
Hi,
It is my code which generates the first row along with pair of student. But when I use loop for 2nd and 3rd row the same students is occured in each column . It won't reply the random value.
It is my code which generates the first row along with pair of student. But when I use loop for 2nd and 3rd row the same students is occured in each column . It won't reply the random value.
Code: Select all
<?php
function in_array_r($avail, $haystack, $strict = false) {
//print_r($avail);
if($haystack == '')
{
unset($haystack);
} else {
foreach ($haystack as $v1) {
foreach ($v1 as $item) {
// echo "array val:".$item."<br/>";
if (($strict ? $item === $avail : $item == $avail) || (is_array($item) && in_array_r($avail, $item, $strict))) {
return true;
}
}
}
}
return false;
}
function select_rand_student($input){
$chk_rand = '';
$length = count($input)/2;
for($k=0;$k <2; $k++)
{
for ($i = 0; $i < $length; $i++) {
$rand_keys = array_rand($input, 2);
//print_r($rand_keys)."<br/>";
if(in_array_r($rand_keys[0], $chk_rand)) {
$i = $i-1;
}
elseif(in_array_r($rand_keys[1], $chk_rand)) {
$i = $i-1;
}
else{
$chk_rand[] = $rand_keys;
$outdata[$k][$i][] = $input[$rand_keys[0]];
$outdata[$k][$i][] = $input[$rand_keys[1]];
}
}
}
return $outdata;
}
$stud_list = array("S1","S2","S3","S4","S5","S6");
$result_stud = select_rand_student($stud_list);
echo '<pre>';
print_r($result_stud);
echo '</pre>';
foreach($result_stud as $pair)
{
foreach($pair as $key=>$val)
{
echo "$key".$val."<br/>";
}
}
}
?>