enum factionInfo
{
FactionRanks,
FactionRank1[24],
FactionRank2[24],
FactionRank3[24],
FactionRank4[24],
FactionRank5[24],
FactionRank6[24],
FactionRank7[24],
FactionRank8[24],
FactionRank9[24],
FactionRank10[24],
FactionRank11[24],
FactionRank12[24],
FactionRank13[24],
FactionRank14[24],
FactionRank15[24]
}
forward OnFactionsLoaded();
public OnFactionsLoaded()
{
new rows, field[10], factionid;
cache_get_row_count(rows);
for (new i; i < rows; i++) if (i < MAX_FACTIONS)
{
cache_get_value_name_int(i, "ID", factionid);
cache_get_value_name_int(i, "Ranks", FactionInfo[factionid][FactionRanks]);
for (new index = 24, number = 1; index <= 360; index += 24, number++)
{
format(field, sizeof(field), "Rank%d", number);
cache_get_value_name(i, field, FactionInfo[factionid][factionInfo:index], 24);
}
}
}
SaveFaction(factionid)
{
new query[500], field[10];
mysql_format(g_MySQL, query, sizeof(query), "UPDATE `factions` SET `Ranks` = %d", FactionInfo[factionid][FactionRanks]);
for (new index = 24, number = 1; index <= 360; index += 24, number++)
{
format(field, sizeof(field), "Rank%d", number);
mysql_format(g_MySQL, query, sizeof(query), "%s, `%s` = '%e'", query, field, FactionInfo[factionid][factionInfo:index]);
}
mysql_format(g_MySQL, query, sizeof(query), "%s WHERE `ID` = %d", query, factionid);
mysql_tquery(g_MySQL, query);
}
printf("%s", FactionInfo[0][FactionRank1]);
printf("%s", FactionInfo[0][FactionRank2]);
printf("%s", FactionInfo[0][FactionRank3]);
printf("%s", FactionInfo[0][FactionRank4]);
printf("%s", FactionInfo[0][FactionRank5]);
printf("%s", FactionInfo[0][FactionRank6]);
printf("%s", FactionInfo[0][FactionRank7]);
printf("%s", FactionInfo[0][FactionRank8]);
printf("%s", FactionInfo[0][FactionRank9]);
printf("%s", FactionInfo[0][FactionRank10]);
printf("%s", FactionInfo[0][FactionRank11]);
printf("%s", FactionInfo[0][FactionRank12]);
printf("%s", FactionInfo[0][FactionRank13]);
printf("%s", FactionInfo[0][FactionRank14]);
printf("%s", FactionInfo[0][FactionRank15]);
printf("%s", FactionInfo[0][factionInfo:24]);
printf("%s", FactionInfo[0][factionInfo:48]);
printf("%s", FactionInfo[0][factionInfo:72]);
printf("%s", FactionInfo[0][factionInfo:96]);
printf("%s", FactionInfo[0][factionInfo:120]);
printf("%s", FactionInfo[0][factionInfo:144]);
printf("%s", FactionInfo[0][factionInfo:168]);
printf("%s", FactionInfo[0][factionInfo:192]);
printf("%s", FactionInfo[0][factionInfo:216]);
printf("%s", FactionInfo[0][factionInfo:240]);
printf("%s", FactionInfo[0][factionInfo:264]);
printf("%s", FactionInfo[0][factionInfo:288]);
printf("%s", FactionInfo[0][factionInfo:312]);
printf("%s", FactionInfo[0][factionInfo:336]);
printf("%s", FactionInfo[0][factionInfo:360]);
est one one one one one one one one one one one one one
test None None None None None None None None None None None None None N ne
UPDATE `factions` SET `Ranks` = 11, `Rank1` = 'test', `Rank2` = 'None', `Rank3` = 'None', `Rank4` = 'None', `Rank5` = 'None', `Rank6` = 'None', `Rank7` = 'None', `Rank8` = 'None', `Rank9` = 'None', `Rank10` = 'None', `Rank11` = 'None', `Rank12` = 'None', `Rank13` = 'None', `Rank14` = 'None', `Rank15` = 'N\nne' WHERE `ID` = 0
| factionId | rankNr | name |
| 1 | 1 | Beginner |
| 1 | 2 | Intermediate |
| 1 | 3 | Expert |
|
The design of the table itself is poor to begin with. If you need to add a number to a column name then you're doing databases wrong. You should have one table "Faction" and another "Rank". The "Rank" table should have 3 columns: factionId, rankNr and rankName. Where factionId and rankNr are the primary key: this is needed to identify the row for update or deletion (update ... where factionid = 1 and rankNr = 5).
|
for (new index = 1, number = 1, until_rank = (FactionInfo[factionid][FactionRanks] - 1) * 24 + 1; index <= until_rank; index += 24, number++)
{
format(field, sizeof(field), "Rank%d", number);
cache_get_value_name(i, field, FactionInfo[factionid][factionInfo:index], 24);
}
enum factionInfo
{
FactionRanks[16][24],
}
|
Diving to more tables is better because if a faction doesn't have many ranks, all the rest of columns would go waste.
About the loop, it's incorrect too. It starts from index 1. pawn Код:
|
DELETE FROM factionranks WHERE ID = 0 AND Rank = 11; DELETE FROM factionranks WHERE ID = 0 AND Rank = 12; DELETE FROM factionranks WHERE ID = 0 AND Rank = 13; DELETE FROM factionranks WHERE ID = 0 AND Rank = 14; DELETE FROM factionranks WHERE ID = 0 AND Rank = 15;
|
Why don't you do it like this? (Not the fix)
Код:
enum factionInfo
{
FactionRanks[16][24],
}
|
|
Oh, thank you. I will divide them. But let's say a faction has 15 ranks and I want to set them to 10, this means I need to delete 5 rows. What would be the best way to do it? Doing
Код:
DELETE FROM factionranks WHERE ID = 0 AND Rank = 11; DELETE FROM factionranks WHERE ID = 0 AND Rank = 12; DELETE FROM factionranks WHERE ID = 0 AND Rank = 13; DELETE FROM factionranks WHERE ID = 0 AND Rank = 14; DELETE FROM factionranks WHERE ID = 0 AND Rank = 15; |
DELETE FROM factionranks WHERE ID = 0 AND Rank >= 11;
DELETE FROM factionranks WHERE ID = 0 AND (Rank >= 11 AND Rank <= 15);
|
Operators work in SQL as well.
pawn Код:
pawn Код:
I was about to edit my post if you hadn't reply and say about this. It is simple - don't use an enumerator for the ranks and avoid all the complicated stuff about finding each index. |
|
Thanks, but if I shouldn't use an enumerator for ranks, then what should I use?
|
new gFaction_Rank[MAX_FACTIONS][15][24];