Command lags the whole server -
danielpalade - 10.01.2017
-- DELETED --
Re: Command lags the whole server -
BiosMarcel - 10.01.2017
https://sampwiki.blast.hk/wiki/MySQL/R40#mysql_query
Read the important notes
Re: Command lags the whole server -
danielpalade - 10.01.2017
Quote:
Originally Posted by [Bios]Marcel
|
And what exactly do I have to do with that information? As I said, that command only lag on one gamemode. Do you an alternative of that command or something? Or is there a better way to do it?
Re: Command lags the whole server -
Lordzy - 10.01.2017
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 `COUNT(*)`, `Member` FROM `players` GROUP BY `Member`
You can even avoid looping using such a query, unless this isn't what that you really want.
Re: Command lags the whole server -
BiosMarcel - 10.01.2017
Quote:
Originally Posted by Lordzy
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 `COUNT(*)`, `Member` FROM `players` GROUP BY `Member`
You can even avoid looping using such a query, unless this isn't what that you really want.
|
What Lordzy said is right, i just wanted to point out that you should use threaded queries
Re: Command lags the whole server -
danielpalade - 10.01.2017
Quote:
Originally Posted by Lordzy
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 `COUNT(*)`, `Member` FROM `players` GROUP BY `Member`
You can even avoid looping using such a query, unless this isn't what that you really want.
|
But the thing is, it should show all the factions when using /factions, thus it should show a different amount of members for each faction.
Re: Command lags the whole server -
Vince - 10.01.2017
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 код:
SELECT member AS factionId, COUNT(*) AS memberCount FROM Player GROUP BY member
produces a result like this:
factionId | memberCount |
2 | 10 |
4 | 8 |
7 | 13 |
Re: Command lags the whole server -
danielpalade - 10.01.2017
Quote:
Originally Posted by Vince
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 код:
SELECT member AS factionId, COUNT(*) AS memberCount FROM Player GROUP BY member
produces a result like this:
factionId | memberCount | 2 | 10 | 4 | 8 | 7 | 13 |
|
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);
Where the variabile I would be a variable in a loop, to loop through all the factions available.
Re: Command lags the whole server -
Vince - 10.01.2017
Quote:
Originally Posted by danielpalade
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);
Where the variabile I would be a variable in a loop, to loop through all the factions available.
|
GROUP BY does that! Just try it already!
Re: Command lags the whole server -
danielpalade - 10.01.2017
Quote:
Originally Posted by Vince
GROUP BY does that! Just try it already!
|
I've tried this:
Код:
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;
}
But it doesn't work. :<