SA-MP Forums Archive
Count clanID numbers - 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: Count clanID numbers (/showthread.php?tid=626514)



Count clanID numbers - Nin9r - 16.01.2017

Hi! I have a problem with my clan system. In database i use auto increment on every /createclan. Some clans will expire and will be deleted.

I am using it in public IniClans:
Код HTML:
for ( new i, j = cache_get_row_count ( ); i != j; ++i )
	{
}
It is wrong because until few months I reached clanID 50+ in database.
cache_get_row_count is counting how many rows i have in database, not the value of clanID`s.

So, for example if i have 7 clans in database, the 'cache_get_row_count' gets the value 7, and 2 of the clans have clanID value 48, 14 (from auto increment)etc... it won't be loaded because it has an clanID above 7. How can I fix it? What function do I have to use to count the maximum value of clanID?


Re: Count clanID numbers - Vince - 16.01.2017

What? How is it important what the clanId even is? It shouldn't be used an index or anything. In your loop i the row id, not the clan id.


Re: Count clanID numbers - Nin9r - 16.01.2017

Ok. But why just few clans will be loaded from database?

I am using:

Код HTML:
public IniClans()
{
	new Cache: result2 = mysql_query (handle, "SELECT * FROM `clans` ORDER BY `clans`.`clanID` ASC");
	new x;

 	for ( new i, j = cache_get_row_count ( ); i != j; ++i )
	{
		cache_get_field_content(i, "clanID", result); x = strval(result);
		cache_get_field_content(i, "clanName", result); format(clanVariables[x][cClanName], 64, result);
		cache_get_field_content(i, "clanTag", result); format(clanVariables[x][cClanTag], 32, result);
		cache_get_field_content(i, "clanRankName1", result); format(clanVariables[x][cClanRankName1], 32, result);
		cache_get_field_content(i, "clanRankName2", result); format(clanVariables[x][cClanRankName2], 32, result);
		cache_get_field_content(i, "clanRankName3", result); format(clanVariables[x][cClanRankName3], 32, result);
		cache_get_field_content(i, "clanRankName4", result); format(clanVariables[x][cClanRankName4], 32, result);
		cache_get_field_content(i, "clanRankName5", result); format(clanVariables[x][cClanRankName5], 32, result);
		cache_get_field_content(i, "clanRankName6", result); format(clanVariables[x][cClanRankName6], 32, result);
		cache_get_field_content(i, "clanRankName7", result); format(clanVariables[x][cClanRankName7], 32, result);
	    cache_get_field_content(i, "clanColor", result); format(clanVariables[x][cClanColor], 32, result);
		cache_get_field_content(i, "clanSlots", result); clanVariables[x][cClanSlots] = strval(result);
		cache_get_field_content(i, "clanDays", result); clanVariables[x][cClanDays] = strval(result);
		cache_get_field_content (i, "clanLeader", result); format(clanVariables[x][cClanLeader], 32, result);

	}
	cache_delete(result2);
	return 1;
}



Re: Count clanID numbers - Vince - 16.01.2017

Like I said, the clanId should not be the array index. You're assigning the clanId to x and then you use x as an array index which is what you should NOT be doing. Create an extra enum specifier and name it SQLClanId or something along those lines. Then assign the clanId to that so you can use it for future update queries. Then use i as the array index.

PHP код:
clanVariables[i][SQLClanId] = cache_get_field_content_int(i"clanID"); 
So then suppose you have clans 1, 2, 3, 4, 5, 14 and 48. The array will contain:

Код:
clanVariables[0][SQLClanId] = 1;
clanVariables[1][SQLClanId] = 2;
clanVariables[2][SQLClanId] = 3;
clanVariables[3][SQLClanId] = 4;
clanVariables[4][SQLClanId] = 5;
clanVariables[5][SQLClanId] = 14;
clanVariables[6][SQLClanId] = 48;