>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


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to