Jump to content

Odd outputs after some loops and counting rows


Recommended Posts

Hey all,

 

I'm trying to create a system to check a scheduling tool I'm developing for teams playing at the same time twice (IE: an error). While I've been able to get a system in place that effectively finds these mismatches, it's outputting a little funny and I'm not sure why.

 

In my demo schedule, I've scheduled two teams (Arsenal 1 [216] and Donkeys [281]) to be playing twice at the same time.. and the table looks like this:

 

db.png

 

and the output is:

 

output.png

 

It makes sense to me the Arsenal error would output twice, but why the Donkeys one comes out 11 times... I have no clue...

 

and finally the code:

 


		<?php

			$team_list_query	= "	SELECT DISTINCT team 
							FROM schedules 
							WHERE league_date = '$league_date' 
							AND league = '$league_selection'
							ORDER BY team ASC";

			$team_list_results	= mysql_query($team_list_query) or die(mysql_error());

		while($row = mysql_fetch_array($team_list_results)){ $team = $row['team']; 

			$time_list_query	= "	SELECT DISTINCT gametime 
							FROM schedules 
							WHERE league_date = '$league_date' 
							AND league = '$league_selection'";

			$time_list_results	= mysql_query($time_list_query) or die(mysql_error());

			while($row = mysql_fetch_array($time_list_results)){ $time = $row['gametime']; 

				$team_name_query	= "	SELECT * FROM team 
								WHERE team_id = '$team'";

				$team_name_results	= mysql_query($team_name_query) or die(mysql_error());

				while($row = mysql_fetch_array($team_name_results)){

					$team_name	= $row['team'];

				}

				$time_strip		= strtotime($time);		

				$gametime	 	= date('g:i A', $time_strip);

				$error_check_query	= "	SELECT * FROM schedules 
								WHERE league_date = '$league_date' 
								AND league = '$league_selection' 
								AND gametime = '$time' 
								AND team = '$team'";

				$error_check_results	= mysql_query($error_check_query) or die(mysql_error());				

				$error_check		= mysql_num_rows($error_check_results);

				if($error_check > 1) {

					$errors = "<span style=\"color: red\"><li>".$team_name." is scheduled for ".$error_check." games at ".$gametime."</span></li><br/>";

				} else { }


			}

				if(empty($errors)) { } else { echo $errors; }

		}

				if(empty($errors)) { echo "<span style=\"color: green\"><li>The schedule is free of errors!</li></span>"; } else { }

				echo "</ul>";

				?>

 

Any ideas or help is greatly appreciated... thanks!

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.