Raised This Month: $51 Target: $400
 12% 

Bug in sql query SELECT SUM?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Lt Llama
Senior Member
Join Date: Aug 2004
Old 02-04-2006 , 10:43   Bug in sql query SELECT SUM?
Reply With Quote #1

Im trying to use the sql SELECT SUM to get the sum of a column.
When I use

Code:
resultMaps = dbi_query(dbcMaps,"SELECT SUM(difficulty) FROM skillmaps where steamId='%s' AND mapName='%s'",authid,mapname)

I get a "[MYSQL] Invalid column name 'difficulty'".

When I tested
Quote:
SELECT SUM(difficulty) FROM `skillmaps`
in phpmyadmin I get the sum.

When I change the code to

Code:
resultMaps = dbi_query(dbcMaps,"SELECT difficulty FROM skillmaps where steamId='%s' AND mapName='%s'",authid,mapname)

I get acces to the column difficulty? How do I get that summed up value in my plugin?

The part of my function which dont work below:

Code:
// Get the sum of collected points new qryDifficulty[10] resultMaps = dbi_query(dbcMaps,"SELECT SUM(difficulty) FROM skillmaps where steamId='%s' AND mapName='%s'",authid,mapname) if (resultMaps <= RESULT_FAILED ) {     log_amx("[AMXX: SKILLRANK] Couldnt sum difficulty. Plugin cancelled.")     return PLUGIN_HANDLED } dbi_nextrow(resultMaps) dbi_result(resultMaps, "difficulty", qryDifficulty, 9) len += format(mapStatsMotd[len], 2047-len,"Collected rank points on this map: %i^n",qryDifficulty) dbi_free_result(resultMaps)
Lt Llama is offline
DaSoul
Senior Member
Join Date: Jan 2006
Old 02-04-2006 , 15:00  
Reply With Quote #2

Try

Code:
resultMaps = dbi_query(dbcMaps,"SELECT SUM(difficulty) as sumdiff FROM skillmaps where steamId='%s' AND mapName='%s'",authid,mapname)

Then instead of using difficulty down below use sumdiff as your column.

Basically:

Code:
// Get the sum of collected points new qryDifficulty[10] resultMaps = dbi_query(dbcMaps,"SELECT SUM(difficulty) as sumdiff FROM skillmaps where steamId='%s' AND mapName='%s'",authid,mapname) if (resultMaps <= RESULT_FAILED ) {     log_amx("[AMXX: SKILLRANK] Couldnt sum difficulty. Plugin cancelled.")     return PLUGIN_HANDLED } dbi_nextrow(resultMaps) dbi_result(resultMaps, "sumdiff", qryDifficulty, 9) len += format(mapStatsMotd[len], 2047-len,"Collected rank points on this map: %i^n",qryDifficulty) dbi_free_result(resultMaps)
DaSoul is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 07:29.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode