Jump to content

Loop within loop outputting results once then stopping


Recommended Posts

Hey all,

 

I'm trying to execute a loop within a loop and it's only outputting the second loop's results once.

 

To summarize what it's doing, the first loop finds all the teams within this schedule, then the second loop finds all the various times the teams might play and counts how many times the team plays at that time... but the output looks like this:

 

281 (team)

-- 0830 (time) - 1 (count)

-- 0920 - 1

-- 1010 - 0

-- 1100 - 0

-- 1150 - 0

279

283

289

278

282

277

280

284

 

Here's the code...

 

		<?php

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

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

		$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($team_list_results)){ $team = $row['team']; 

		echo $team."<br/>";

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

			$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);

			echo "-- ".$time." - ".$error_check."<br/>";

		}

	}

 

Any help is greatly appreciated -- thanks!

The first time you run through the inner loop it will move the pointer to the end of the dataset $time_list_results, so the second time through the outter loop the inner loop won't even be entered because the first call to mysql_fetch_array will return FALSE. I've never actually used the function so I could be wrong, but I think what your after may be mysql_data_seek (that is of course assuming it allows you to track backwards).

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.