MySQL COUNT
#1

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
Reply
#2

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
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)