ranjitcool — 2005-05-14T02:26:34-04:00 — #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");
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??
goldfire — 2005-05-14T02:35:16-04:00 — #2
Change your code to the following:
$sum = mysql_fetch_array(mysql_query("SELECT SUM(score) FROM username WHERE optionno = correct"));
ranjitcool — 2005-05-14T02:44:01-04:00 — #3
BUT WHY DOES that give that error is that an error?
bigduke — 2005-05-14T03:02:11-04:00 — #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'"));
goldfire — 2005-05-14T11:48:43-04:00 — #5
No, the way I posted it is correct because that is not a string it is a field in the table.
luke_redpath — 2005-05-14T20:14:57-04:00 — #6
No, he is correct. This part:
WHERE optionno = 'correct'"
Does need the quotes as you are testing for the string 'correct'.
goldfire — 2005-05-14T20:50:25-04:00 — #7
I already talked to ranjitcool over PM and he told me that correct was a field in his table.
luke_redpath — 2005-05-14T23:46:00-04:00 — #8
Mmm, perhaps a better naming convention is in order!