PHP - Scheduler
I am working on my admin panel for a client and i am having a problem with creating an automatic scheduler.
The problem I am having is that if the teams already played its not redoing the for loop how can i make it do the for loop again? Code: [Select] <?php //Automatic Scheduler for leagues and such //Load custom mysql class for this project include("class.mysql.php"); //start MySql instance $my = new MySql; //get the number of teams $num = $my->getNum("SELECT id FROM teams"); //if number of teams are odd add a dummy team for a BYE week if ($num%2 != 0) { //create dummy team called BYE $my->insert('Teams',array("Name" => "BYE")); } //do the necessary calculations $number_of_teams = $num; $number_of_weeks = $number_of_teams * 2 - 2; $number_of_matches_per_week = $number_of_teams/2; $total_number_of_matches = $number_of_weeks * $number_of_matches_per_week; //start the week for statment for ($i = 1; $i <= $number_of_weeks; $i++) { //get all the teams in an array $teams = $my->getArray("SELECT id,name FROM teams"); shuffle($teams); for ($b = 1; $b <= $number_of_matches_per_week; $b++) { //get random teams $aid = array_rand($teams); $hid = array_rand($teams); //check to see if the teams have played each other if they have it will return FALSE if ($my->checkTeams($aid,$hid)) { //create match $my->createMatch($aid,$hid,$i); } else { //do it again $b--; } } } ?> Similar TutorialsNeed help the page doesnt do anything, if anyone could guide me in helping me make this work and more efficient I am making a weekley scheduler if the team have either played this week dont schedule or if the two teams have played each other in previous weeks dont schedule them together here is my scheduler class <?php class scheduler { var $week; var $max_teams; function scheduler() { global $Settings; $get_all = mysql_query("SELECT * FROM teams"); $this->max_teams = mysql_num_rows($get_all); if ($Settings->week == 'Not Started') { $this->week = 1; } else { $this->week = $Settings->week; } } function CheckTeams($team1,$team2) { //check if the two teams have played at all //this season if ($this->checkPlay($team1,$team2)) { return true; } else { return false; } } function checkPlay ($team1,$team2) { $week = $this->week; $check = mysql_query("SELECT * FROM matches WHERE team1 = '".$team1."' AND team2 = '".$team2."' OR team1 = '".$team2."' AND team2 = '".$team1."'"); $num = mysql_num_rows($check); if ($num > 0) { return false; } else { $check = mysql_query("SELECT * FROM matches WHERE `team1` = '".$team1."' OR `team2` = '".$team1."' AND `week` = '".$week."' "); $nums = mysql_num_rows($check); if ($nums > 0) { return false; } else { $check = mysql_query("SELECT * FROM matches WHERE `team1` = '".$team2."' OR `team2` = '".$team2."' AND `week` = '".$week."' "); $nums = mysql_num_rows($check); if ($nums > 0) { return false; } else { return true; } } } } function createMatch ($team1,$team2) { $create = mysql_query("INSERT INTO matches (`team1`, `team2`) VALUES ('$team1','$team2')"); if ($create) { return true; } else { return false; } } } ?> here is my other script <?php //get all teams first and set them in available array $get_all = mysql_query("SELECT * FROM teams"); $max_teams = mysql_num_rows($get_all); $i = 1; $rand_team = rand(1,$max_teams); while($team = mysql_fetch_assoc($get_all)) { $available[$i] = $team['teamname']; $i++; } // end getting all teams for ($i = 1; $i < $Scheduler->max_teams; $i++) { //get the two teams $get_team1 = rand(1,$Scheduler->max_teams); $get_team2 = rand(1,$Scheduler->max_teams); $team1 = $available[$get_team1]; $team2 = $available[$get_team2]; if ($Scheduler->CheckTeams($team1,$team2)) { if ($Scheduler->createMatch($team1,$team2)) { echo 'Scheduled '.$team1.' to play '.$team2.' in week '.$Scheduler->week.'<br />'; } }else { $i--; } } ?> Hello, I am fairly new at php (have been using HTML/CSS for a while but recently learned the php basics). I am building a website to allow clients to schedule through multiple massage therapists and I am struggling with the basic beginings of a scheduler scripts. If someone can point me towards a tutorial or script that would be great, or answer any of the following questions: 1. What would be the best way to store each therapists weekly schedule (based on monday-sunday with start and end times) and propagate that info. to every day that a client might schedule on? 2. How do i get the day of the week based on the date? 3. How do i display a calendar that lets them choose the date? Can someone help me out with making a bat file. I cant find a good set of directions on google. I have window scheduler all working in running but it runs my script in note pad and not IE like I need it too. I also read something about php cgi file for doing this same thing but cant make heads of tails out of it from reading about it in the manual. Trying to run this http://localhost/gate/users/update.php |