SA-MP Forums Archive
MySQL COUNT - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: MySQL COUNT (/showthread.php?tid=564874)



MySQL COUNT - Derexi - 23.02.2015

I'm trying to add all the players in a group's scores up with MySQL. I've written this query:

pawn Код:
mysql_format(conhand, query2, sizeof(query2), "SELECT COUNT(score) FROM users WHERE group_id = %d", groupid);
    mysql_pquery(conhand, query2, "OnGroupScoreCount");
But now, how do I get the result? What function do I use under OnGroupScoreCount? :S


Re: MySQL COUNT - Misiur - 23.02.2015

You can use normal
pawn Код:
cache_get_row_int(0, 0, conhand);
to fetch first field of first row (as it's an aggregate result there will always be 1 row and 1 field).

If you'd rather use field name, I'd suggest using an alias for that:
Quote:

SELECT COUNT(score) AS score_count FROM users WHERE group_id = %d

pawn Код:
cache_get_field_content_int(0, "score_count", conhand);
Then you can simply