Resource id #6 ? what is this headache


#1

i used this line in mysql with php to calculate the sum of a row ...

$sum=mysql_query("select SUM(score) from username where optionno = correct");

echo $sum;

now this gives output Resource id #6

what on earth does that mean please help people...i am new and learning and i wanna solve this ...how do i do with the script??


#2

Change your code to the following:

$sum = mysql_fetch_array(mysql_query("SELECT SUM(score) FROM username WHERE optionno = correct"));
echo $sum[0];


#3

BUT WHY DOES that give that error is that an error?


#4

thats not an error it simply tells you what the variable holds, in this case its a resource id, much like a handle.

also, your query should put strings in quotes:

$sum = mysql_fetch_array(mysql_query("SELECT SUM(score) FROM username WHERE optionno = 'correct'"));
echo $sum[0];


#5

No, the way I posted it is correct because that is not a string it is a field in the table.


#6

No, he is correct. This part:

WHERE optionno = 'correct'"

Does need the quotes as you are testing for the string 'correct'.


#7

I already talked to ranjitcool over PM and he told me that correct was a field in his table.


#8

Mmm, perhaps a better naming convention is in order!


closed #9