...

View Full Version : Can someone please look at this PHP code and tell me why my loop isn't working...



BigToque
10-07-2005, 06:51 AM
I've been going over this for over an hour and I can't find what's wrong.

Any help is very much appreciated.



<?
$id = $_GET["id"];
$leagueID = $_GET["leagueID"];
$numberOfSeasons = 3;
$season = array("Pre-Season Schedule", "Regular Season Schedule", "Playoff Schedule");

// Get total games played
$query = "SELECT id FROM recaps WHERE year = " . $id . " ORDER BY id DESC LIMIT 0, 1";
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
$numGames = mysql_fetch_row($result);

echo "<h1>" . $id . " " . $leagueID . " " . "Schedule</h1>";

//print schedule
for ($count=0; $count < $numberOfSeasons; $count++) {
echo '<p class="underline">' . $season[($count)] . '</p>';

$query = "SELECT id, date, time, rink, opponent, result, GF, GA FROM schedule WHERE year = " . $id . " AND league = " . "'" . $leagueID . "'". " AND season = " . ($count + 1);
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
$numrows = mysql_num_rows($result);

echo "<table>";
echo '<tr class="bold"><td>Date</td><td>Time</td><td>Rink</td><td>Opponent</td><td>Result</td><td></td></tr>';

for ($count=0; $count < $numrows; $count++){
$id = mysql_result($result, $count, id);
$date = mysql_result($result , $count, date);
$time = mysql_result($result, $count, time);
$rink = mysql_result($result, $count, rink);
$opponent = mysql_result($result, $count, opponent);
$gameResult = mysql_result($result, $count, result);
$gf = mysql_result($result, $count, GF);
$ga = mysql_result($result, $count, GA);

echo "<tr>";
echo "<td>" . date('M j, Y', strtotime($date)) . "</td>" ;
echo "<td>" . date('g:i A', strtotime($time)) . "</td>" ;
echo "<td>" . $rink . "</td>";
echo "<td>" . $opponent . "</td>";

if ($gameResult != ""){
echo "<td>" . $gameResult . " " . $gf . " - " . $ga . "</td>";
}

if ($id <= $numGames[0]){
echo "<td><a href=" . '"recaps.php?id=' . $id . '"' . ">Recap</a></td>";
}
echo "</tr>";
}

echo "</table>";
echo "<br/><br/>";
}

maghiel
10-07-2005, 10:35 AM
if i see it correctly(didn't really read your code good ;)) you have a loop in a loop, and you are using the same var for both loops.
$count in the second loop to something else.

pjleonhardt
10-07-2005, 11:04 AM
I concur with maghiel.. That is most likely the culprit. Try changing the second count to $count2 or... $j... or some other unique variable.

maghiel
10-07-2005, 11:08 AM
it is common to use $i and $n for loops btw.

BigToque
10-07-2005, 02:51 PM
You solved the problem for me... Thanks guys.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum