Jump to content

Resource id #7 error


Go to solution Solved by kicken,

Recommended Posts

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

team_2.pngTony Romo QB - Dallas Cowboys
 
 
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. 
Link to comment
https://forums.phpfreaks.com/topic/281332-resource-id-7-error/
Share on other sites

  • Solution

Look at the HTML output produced by your script so you can identify exactly where the text is being output at, then find that location in your PHP script.

 

Basically the text 'Resource id #X' occurs when you attempt to convert an internal PHP resource (such as that returned by mysql_query) into a string. My best guess as to the reason you are seeing that text is that you may be using $playerinfo previously in your script to hold the result of a mysql_query call. Because you never seem to clear the value, when your script later does:

 

$playerinfo.= "<div class='title'>....
it will attempt to concatenate the html onto the end of the resource, causing the resource-to-string conversion resulting in the text appearing at the top.
Link to comment
https://forums.phpfreaks.com/topic/281332-resource-id-7-error/#findComment-1445716
Share on other sites

Well, you're a genius. Exactly what was happening (i.e. $playerinfo was used previously in the script to hold the result of a mysql query call).  Thanks for not only that "guess" but also for the explanation about why it was giving that error (you're explanation made more sense than all of the google search results i looked up on that specific error).

 

Anyway, thanks again so much Kicken!

Link to comment
https://forums.phpfreaks.com/topic/281332-resource-id-7-error/#findComment-1445718
Share on other sites

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.