Page 1 of 1

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

Posted: Mon Jul 19, 2010 2:35 pm
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>";
	}

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

Posted: Mon Jul 19, 2010 2:41 pm
by AbraCadaver
$statusname is a result set. You need to use one of the mysql_fetch_*() functions to get data from it.

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

Posted: Mon Jul 19, 2010 2:44 pm
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!

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

Posted: Mon Jul 19, 2010 3:28 pm
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.