BigBrother Posted February 8, 2009 Share Posted February 8, 2009 Hi need help with this. I am trying to create a schedule for 20 teams, howerver if the number of teams is changed to 20 the script errors out schedule_class.php <?php class schedule{ var $history=array(); var $num=8; var $a=array(); function make_teams(){ for($i=1;$i<=$this->num;$i++){ $this->a[]="team ".$i; } } function remove_history($team1,$team2){ if(sizeof($this->history)>0){ foreach($this->history[$team1] as $key => $val){ if($val==$team2&&$val){ $this->history[$team1][$key]=0; break; } } } } function make_history(){ for($i=0;$i<$this->num;$i++){ for($j=0;$j<$this->num;$j++){ if($i==$j) $this->history[$this->a[$i]][]=0; else $this->history[$this->a[$i]][]=$this->a[$j]; } } } function print_teams(){ print_r($this->teams); } function check_temp_history($temphistory,$team){ if(sizeof($temphistory)>0){ foreach($temphistory as $val){ if($val==$team){ return false; } } } return true; } function move(){ $temphistory=array(); for($i=0;$i<$this->num;$i++){ if(sizeof($this->history)>0){ foreach($this->history[$this->a[$i]] as $key => $val){ if($val&&$this->check_temp_history($temphistory,$val)&&$this->check_temp_history($temphistory,$this->a[$i])){ $temphistory[]=$this->a[$i]; $temphistory[]=$val; break; } } } } $this->a=$temphistory; } function run(){ for($j=1;$j<$this->num;$j++){ for($i=0;$i<$this->num;$i+=2){ srand(); $r=rand(0,1); if($r==1){ echo $this->a[$i]."-".$this->a[$i+1]; } else{ echo $this->a[$i+1]."-".$this->a[$i]; } echo "<br />"; $this->remove_history($this->a[$i],$this->a[$i+1]); $this->remove_history($this->a[$i+1],$this->a[$i]); } echo "<hr>"; $this->move(); } } } ?> schedule.php <?php include("schedule_class.php"); $s=new schedule(); //number of teams $s->num=8; //makes the teams $s->make_teams(); //makes the history-all the possibilities of the teams(team1 can play against all and so on) $s->make_history(); //prints the schedule $s->run(); ?> Any ideas peeps... thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/144337-help-needed-with-schedule/ Share on other sites More sharing options...
revraz Posted February 8, 2009 Share Posted February 8, 2009 Posting what "error out" means helps. Quote Link to comment https://forums.phpfreaks.com/topic/144337-help-needed-with-schedule/#findComment-757461 Share on other sites More sharing options...
.josh Posted February 8, 2009 Share Posted February 8, 2009 in your make_history() and move() methods, you forgot to specify the element in the sizeof() condition. Also, move is a reserved word. You might want to change that to something else. Quote Link to comment https://forums.phpfreaks.com/topic/144337-help-needed-with-schedule/#findComment-757500 Share on other sites More sharing options...
.josh Posted February 8, 2009 Share Posted February 8, 2009 oops I meant remove_history() not make_history() ( and the move() ) Quote Link to comment https://forums.phpfreaks.com/topic/144337-help-needed-with-schedule/#findComment-757501 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.