Command lags the whole server
#1

-- DELETED --
Reply
#2

https://sampwiki.blast.hk/wiki/MySQL/R40#mysql_query

Read the important notes
Reply
#3

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?
Reply
#4

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.
Reply
#5

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

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

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 factionIdCOUNT(*) AS memberCount FROM Player GROUP BY member 
produces a result like this:
factionId memberCount
2 10
4 8
7 13
Reply
#8

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 factionIdCOUNT(*) 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.
Reply
#9

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!
Reply
#10

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. :<
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)