04.04.2019, 06:20
Often problems can be solved by re-writing your code.
This code is cleanly rewritten and doesn't fetch the row count over and over for looping. The query buffer length is 30 characters max, but you used 150. Although, the problem is not visible in the code you've presented, but why save everything when it is most probably not changed? Just save the data when it's changed, like if an admin (or clan leader) renames, then it saves the clan name only and doesn't otherwise.
This code is cleanly rewritten and doesn't fetch the row count over and over for looping. The query buffer length is 30 characters max, but you used 150. Although, the problem is not visible in the code you've presented, but why save everything when it is most probably not changed? Just save the data when it's changed, like if an admin (or clan leader) renames, then it saves the clan name only and doesn't otherwise.
PHP Code:
#define MAX_CLAN_NAME_LEN (32)
forward LoadClans();
public LoadClans() {
new
query[45];
mysql_format(Database, query, sizeof query, "SELECT * FROM `clans` LIMIT %i", MAX_CLANS);
mysql_tquery(Database, query, "OnClansLoad");
return 1;
}
forward OnClansLoad();
public OnClansLoad() {
new
rows;
cache_get_row_count(rows);
if(!rows)
printf("[SERVER]: No clans were loaded from the MySQL Database.");
for(new i = 0; i != rows; i ++) {
cache_get_value_name_int(i, "ClanID", ClanInfo[i][ClanID]);
cache_get_value_name(i, "ClanName", ClanInfo[i][ClanName]);
cache_get_value_name(i, "ClanLeader", ClanInfo[i][ClanLeader]);
cache_get_value_name_int(i, "ClanColor", ClanInfo[i][ClanColor]);
cache_get_value_name_int(i, "ColorSet", ClanInfo[i][ColorSet]);
cache_get_value_name_int(i, "ClanKills", ClanInfo[i][ClanKills]);
cache_get_value_name_int(i, "ClanDeaths", ClanInfo[i][ClanDeaths]);
cache_get_value_name_int(i, "ClanOfficial", ClanInfo[i][ClanOfficial]);
}
printf("[SERVER]: %d clans were loaded from the MySQL Database.", rows);
}