I have code for a football related website that is kicking a "Resource id #7" error. Everything is working right and outputting the proper data, but it also outputs "Resource id #7". I have googled and feel like there is a different reason given with each new google result i click through and read.
Basically the code gets schedule info from one table called "schedule" and then loops through an array called "leavingplayerids", which as an example, looks like this below (when there is only one player, which still kicks the error)...
Array ( [28] => Array ( [1] => Array ( [playerid] => 28 [ranking] => 11 [positionid] => 1 [lastname] => Romo [firstname] => Tony [teamid] => 2 [feet] => 0 [inches] => 0 [weight] => 0 [born] => 0000-00-00 [college] => [display] => YES [ppradjustment] => 0 [injured] => [buylowsellhigh] => [week1] => 11 [week2] => 0 [week3] => 0 [week4] => 0 [week5] => 0 [week6] => 0 [week7] => 0 [week8] => 0 [week9] => 0 [week10] => 0 [week11] => 0 [week12] => 0 [week13] => 0 [week14] => 0 [week15] => 0 [week16] => 0 [week17] => 0 [sportid] => 1 [position] => qb [nickname] => Cowboys [location] => Dallas [qb_matchup] => [rb_matchup] => good [wr_matchup] => [te_matchup] => [pk_matchup] => [def_matchup] => good [starters_before] => 1 [bench_before] => 0 [starters_leaving] => 1 [starters_coming] => 0 [bench_after] => 0 [starters_after] => 0 ) ) )
This is the code which ultimately gives the Resource id #7 error.
// get schedule info for all involved players, $sql = "SELECT h.nickname AS home, a.nickname AS away, h.teamid AS homeid, a.teamid AS awayid, s.weekno FROM schedule s INNER JOIN teams h ON s.homeid = h.teamid LEFT JOIN teams a ON s.awayid = a.teamid WHERE s.seasonno =2013"; $schedule= mysql_query($sql, $connection); if (!$schedule) { die("Database query failed: " . mysql_error()); } else { // Placeholder for data $data = array(); // Loop through results while($row = mysql_fetch_assoc($schedule)) { // Store the results in an ordered array. Lets say the // home team is redskins, away team is cowboys for this // iteration (week 1) if ($row['away'] == "") {$row['away']="BYE";} $data[$row['homeid']][$row['weekno']] = $row['away']; // results in $data['redskins'][1] = 'cowboys' // now results $data[4][1] = 'cowboys' $data[$row['awayid']][$row['weekno']] = '@ '.$row['home']; // results in $data['cowboys'][1] = '@redskins' // now results $data[2][1] = '@redskins' // with this format, we can easily loop through each team // then each week, and it will contain the correct opponent // with the correct location } // I'd then loop through the placeholder // If you want to order by team names ksort($data); } //cycle through each player LEAVING foreach( $leavingplayerids as $ID => $row ) { foreach( $row as $playerID => $info ) { //cycle through the array holding all schedule info foreach( $data as $team => $weeks ) { // Sort weeks low to high ksort($weeks); //see if the current teamid matches the teamid of the current leaving player if ($team == $info['teamid']) { // Output the current player info $playerinfo.= "<div class='title'><img class='helmet' src='images/helmets/team_" . $info['teamid'] . ".png' width=20 /><span class='buysellpagename'><span class='bold'>" . $info['firstname'] . " " . $info['lastname'] . "</span> " . strtoupper($info['position']) . " - " . $info['location'] . " " . $info['nickname'] . "</span></div>"; // Loop through weeks $weekhtml .= "<tr class='week'>"; $opponenthtml .= "<tr>"; foreach( $weeks as $number => $opponent ) { // Output the current week number and opponent $weekhtml .= "<td>Week $number</td>"; $opponenthtml .= "<td>$opponent</td>"; } $weekhtml .= "</tr>"; $opponenthtml .= "</tr>"; $leavingschedules .= $playerinfo . "<table class='schedule' cellpadding=0 cellspacing=0>" . $weekhtml . $opponenthtml . "</table>"; $weekhtml=""; //reset $opponenthtml=""; //reset $playerinfo=""; //reset } else { //do nothing } } } }
This is what gets displayed:
Resource id #7

If anyone notices anything in the code above that might be causing this error, please let me know and I'll try fixing and retesting.