Re: Resource ID??

From: Date: Tue, 03 Sep 2002 18:28:24 +0000
Subject: Re: Resource ID??
Groups: php.general 
Request: Send a blank email to php-general+get-115071@lists.php.net to get a copy of this message
>When trying to do this query: > >$rsum =mysql_query("SELECT SUM(rating) FROM ratings where threadid = $ratevar")or >die (mysql_error()); > >This is the output: >Resource id #15 >or some other seemingly arbitrary Resource ID number? >First of all what is a resource ID and second how do I get it to actually >show what I am trying to get it to show! When you send a query to MySQL, you don't get your actual answer. You get a "Resource ID" It's more like a Receipt for your answer than your answer. You then need to use http://php.net/mysql_fetch_row or other functions to get your actual answer. It does seem a bit like jumping through "extra" hoops to a newbie, but there are some behind-the-scenes technical reasons why you don't just get your "answer" Something like this would work for the above example, after you GET RID of the die() part: if ($rsum){ $ratingsum = mysql_result($rsum, 0, 0); echo "Rating Sum is $ratingsum<BR>\n"; } else{ echo "Web-site down for maintenance. Please try again later.<BR>\n"; error_log(mysql_error()); # NOTE: You have 'broken' SQL. Check you Apache error_log to find the error message } If you were getting several rows, it would be more like: if ($rsum){ while (list($column1, $column2, $column3) = mysql_fetch_row($rsum)){ echo "$column1, $column2, $column3<BR>\n"; } else{ ... same stuff as above } -- Like Music? http://l-i-e.com/artists.htm

« previous php.general (#115071) next »