need logical code for rotational schedule

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
vijayalakshmi
Forum Newbie
Posts: 8
Joined: Tue Jan 21, 2014 10:22 pm

need logical code for rotational schedule

Post by vijayalakshmi »

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.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: need logical code for rotational schedule

Post by Celauran »

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

Post by vijayalakshmi »

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.

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/>";
	  }
  }
}
?>
Post Reply