Resource id #5

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Linx
Forum Newbie
Posts: 3
Joined: Thu Feb 03, 2011 8:36 am

Resource id #5

Post by Linx »

Hello. I have one code but its shows echo "Resource id #5". How to fix it?
Thanks

Code: Select all

$name = $_POST["player_name"]; 
$sql = mysql_query("SELECT * FROM player_extra WHERE name = '".$name."'");
while($row = mysql_fetch_assoc($sql)) {
$id = $row['player_id'];
$sql2 = mysql_query("SELECT * FROM player_race WHERE id = '".$id."' ORDER BY race_id");
$row2 = mysql_fetch_assoc($sql2);

echo "<table border='1'>
<tr>
<th>user</th>
<th>Points</th>
</tr>";

 echo "<tr>";
  echo "<td>". $name. "</td>";
  echo "<td>" .$sql2. "</td>";
  echo "</tr>";
echo "</table>";
}
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Resource id #5

Post by AbraCadaver »

Don't echo $sql2.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Resource id #5

Post by AbraCadaver »

Also, one query might be better:

[text]SELECT * FROM player_extra, player_race
WHERE player_extra.name = '$name'
AND player_extra.player_id = player_race.id
ORDER BY race_id[/text]
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Linx
Forum Newbie
Posts: 3
Joined: Thu Feb 03, 2011 8:36 am

Re: Resource id #5

Post by Linx »

I chanded sql2 echo to row2 and now its says "Array"
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Resource id #5

Post by AbraCadaver »

Linx wrote:I chanded sql2 echo to row2 and now its says "Array"
You did it properly before the loop:

Code: Select all

$id = $row['player_id'];
Maybe:

Code: Select all

echo $row2['something'];
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
User avatar
Mordred
DevNet Resident
Posts: 1579
Joined: Sun Sep 03, 2006 5:19 am
Location: Sofia, Bulgaria

Re: Resource id #5

Post by Mordred »

Also read about SQL injection and mysql_real_escape_string
Post Reply