Resource Id error caused by 1 line of coding. Can you help?

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
tom8521
Forum Commoner
Posts: 25
Joined: Thu May 13, 2010 6:24 am

Resource Id error caused by 1 line of coding. Can you help?

Post by tom8521 »

Not the best with PHP, so I'm sure you immediately see the problem here.

Everything works, but I get a Resource Id error for the statement I placed within the { } 's.

Code: Select all

$result = mysql_query("SELECT * FROM status ORDER BY Date desc LIMIT 0, 3");

while($row = mysql_fetch_array($result))
  {
  $test = $row['User'];
  $statusname = mysql_query("SELECT Screenname FROM sau WHERE Id=$test");
	echo $statusname;
	echo "<div id=\"status-feed-main\"><div id=\"user-pic\"></div><div id=\"status-title\">" . $row['User'] . " says: " . $row['Status'] . "<br /><br /></div>";
	echo "<div id=\"status-date\">" . date("l jS F Y, g:i A", strtotime($row['Date'])) . "</div>";
	echo "</div>";
	}
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Resource Id error caused by 1 line of coding. Can you he

Post by AbraCadaver »

$statusname is a result set. You need to use one of the mysql_fetch_*() functions to get data from it.
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.
tom8521
Forum Commoner
Posts: 25
Joined: Thu May 13, 2010 6:24 am

Re: Resource Id error caused by 1 line of coding. Can you he

Post by tom8521 »

New terminology I have discovered from the last post:

Result Set
mysql_fetch_*() functions

I am no PHP whizz, and could ideally do with someone explaining in English, and possibly typing the answer so I can see where I went wrong.

Thanks!
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Resource Id error caused by 1 line of coding. Can you he

Post by AbraCadaver »

OK, so look at your code. You ran a query and assigned the result to $result. You then fetched a row into $row with mysql_fetch_array($result) so that you could access the data ($row['User'], etc...). That is the proper way, so just follow the same steps with your next query.
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.
Post Reply