chriscloyd Posted October 16, 2010 Share Posted October 16, 2010 Need 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--; } } ?> Quote Link to comment Share on other sites More sharing options...
chriscloyd Posted October 16, 2010 Author Share Posted October 16, 2010 Oh I do have the array set its above the part of the bot script i forgot to add it its $available = array(); Quote Link to comment Share on other sites More sharing options...
chriscloyd Posted October 16, 2010 Author Share Posted October 16, 2010 Fatal error: Maximum execution time of 30 seconds exceeded in /home/lolleagu/public_html/test.php on line 32 Quote Link to comment Share on other sites More sharing options...
ohdang888 Posted October 16, 2010 Share Posted October 16, 2010 you're probably stuck in an infinite loop on your FOR loop Quote Link to comment Share on other sites More sharing options...
chriscloyd Posted October 16, 2010 Author Share Posted October 16, 2010 ya i think i am so how do i get out haha i update my script and it schedules it but it still comes up with the error class scheduler <?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 ($team1 == $team2) { return false; } if ($this->checkPlay($team1,$team2)) { return true; } else { return false; } } function checkTeam ($team) { $check = mysql_query("SELECT * FROM matches WHERE team1 = '".$team."' OR team2 = '".$team."' AND week = '".$this->week."'"); $num = mysql_num_rows($check); if ($num > 0) { return false; } else { return true; } } 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 { return true; } } function createMatch ($team1,$team2) { $week = $this->week; $create = mysql_query("INSERT INTO matches (`team1`, `team2`, `week`) VALUES ('$team1','$team2', '$week')"); if ($create) { return true; } else { return false; } } } ?> the index page to schedule and show results <?PHP session_start(); mysql_connect('localhost',******,******); mysql_select_db(******); include("classes/settings.php"); include("classes/scheduler.php"); $Scheduler = new scheduler; //set arrarys $available = array(); $playing = array(); //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->checkTeam($team1)) { if ($Scheduler->checkTeam($team2)) { if ($Scheduler->CheckTeams($team1,$team2)) { if ($Scheduler->createMatch($team1,$team2)) { echo 'Scheduled '.$team1.' to play '.$team2.' in week '.$Scheduler->week.'<br />'; ; } else { $i--; } } else { $i--; } } else { $i--; } } else { $i--; } } ?> Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted October 17, 2010 Share Posted October 17, 2010 your queries will likely fetch all rows where team1 = '".$team."' regardless of any of the rest of the query. You need to fix your conditions with parentheses. $check = mysql_query("SELECT * FROM matches WHERE team1 = '".$team1."' AND team2 = '".$team2."' OR team1 = '".$team2."' AND team2 = '".$team1."'"); SHOULD BE: $check = mysql_query("SELECT * FROM matches WHERE (team1 = '".$team1."' AND team2 = '".$team2."') OR (team1 = '".$team2."' AND team2 = '".$team1."'")) or die(mysql_error()); Quote Link to comment 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.