10.01.2017, 00:12
(
Последний раз редактировалось danielpalade; 25.09.2017 в 22:00.
)
-- DELETED --
SELECT `COUNT(*)`, `Member` FROM `players` GROUP BY `Member`
You're selecting every rows and columns to know the total players per ffaction. Here you're performing such query (sizeof(E_GROUP)) times that aren't even threaded ones. You could use GROUP BY clause to retrieve the information you're looking for.
pawn Код:
|
You're selecting every rows and columns to know the total players per ffaction. Here you're performing such query (sizeof(E_GROUP)) times that aren't even threaded ones. You could use GROUP BY clause to retrieve the information you're looking for.
pawn Код:
|
SELECT member AS factionId, COUNT(*) AS memberCount FROM Player GROUP BY member
factionId | memberCount |
2 | 10 |
4 | 8 |
7 | 13 |
Yes. GROUP BY does that and it produces one result set that can be read in one go. I usually switch the columns around so groupid is first and member count is second, but it shouldn't matter. A query like this:
PHP код:
|
format(string, sizeof(string), "SELECT COUNT(*) FROM `players` WHERE `Member` = '%d'", i);
But the thing is, I need to calculate how many users are in that faction ID.
I don't have a column or something that stores the amount of players in it. I need something like Код:
format(string, sizeof(string), "SELECT COUNT(*) FROM `players` WHERE `Member` = '%d'", i); |
CMD:factions(playerid, params[]) { new Cache: r, rows, small[128], string[2000], query[256], members, factionId, memberCount[sizeof(E_GROUP)]; r = mysql_query(dbHandle, "SELECT Member AS factionId, COUNT(*) AS memberCount FROM players GROUP BY Member", true); rows = cache_num_rows(); for (new c = 0; c < rows; c++) { factionId = cache_get_row_int(c, 0); memberCount[factionId] ++; } cache_delete®; format(small, sizeof(small), "Faction\tSlots\n"); for(new i; i < sizeof(E_GROUP); i++) { format(string, sizeof(string), "%s%s\t%d/%d", small, E_GROUP[i][gName], memberCount[i], E_GROUP[i][gSlots]); } ShowPlayerDialog(playerid, DIALOG_FACTIONS, DIALOG_STYLE_TABLIST_HEADERS,"Factions", string, "Select", "Cancel"); return 1; }