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");
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??
Change your code to the following:
$sum = mysql_fetch_array(mysql_query("SELECT SUM(score) FROM username WHERE optionno = correct"));
BUT WHY DOES that give that error is that an error?
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'"));
No, the way I posted it is correct because that is not a string it is a field in the table.
No, he is correct. This part:
WHERE optionno = 'correct'"
Does need the quotes as you are testing for the string 'correct'.
I already talked to ranjitcool over PM and he told me that correct was a field in his table.
Mmm, perhaps a better naming convention is in order!
This topic is now closed. New replies are no longer allowed.