forward LoadFactions();
public LoadFactions()
{
new Query[300];
for(new i = 0; i < MAX_FACTIONS; i++)
{
format(Query, sizeof(Query), "SELECT * FROM `Factions` WHERE `FactionID` = '%s' ", FactionCount);
mysql_query(Query);
mysql_store_result();
mysql_fetch_row_format(Query);
sscanf(Query, "e<p<|>is[128]s[128]dfff>", FInfo[i]);
mysql_free_result();
FactionCount++;
new string[128];
format(string,sizeof(string),"Faction Name: %s \nOwned by: %s\nFaction Value: %d",FInfo[i][Name],FInfo[i][Owner],FInfo[i][Value]);
CreateDynamicPickup(1239,1,FInfo[i][LocationX],FInfo[i][LocationY],FInfo[i][LocationZ],-1,-1,-1,100.0);
CreateDynamic3DTextLabel(string,COLOR_RED,FInfo[i][LocationX],FInfo[i][LocationY],FInfo[i][LocationZ],100.0);
}
}
for(new i = 0; i < MAX_FACTIONS; i++)
{
format(Query, sizeof(Query), "SELECT * FROM `Factions` WHERE `FactionID` = '%s' ", FactionCount);
forward LoadFactions();
public LoadFactions()
{
new
Query[300],
string[128],
FactionCount;
mysql_query("SELECT * FROM Factions");
mysql_store_result();
while(mysql_fetch_row_format(Query, "|"))
{
sscanf(Query, "e<p<|>is[128]s[128]dfff>", FInfo[i]);
format(string,sizeof(string),"Faction Name: %s \nOwned by: %s\nFaction Value: %d", FInfo[i][Name], FInfo[i][Owner], FInfo[i][Value]);
CreateDynamicPickup(1239, 1, FInfo[i][LocationX], FInfo[i][LocationY], FInfo[i][LocationZ], -1, -1, -1, 100.0);
CreateDynamic3DTextLabel(string, COLOR_RED, FInfo[i][LocationX], FInfo[i][LocationY], FInfo[i][LocationZ], 100.0);
FactionCount++;
}
mysql_free_result();
return FactionCount;
}
pawn Код:
pawn Код:
|
forward SaveFactions();
public SaveFactions()
{
for(new i = 0; i < FactionCount; i++)
{
new query[1024];
format(query, sizeof(query), "UPDATE Factions SET \
FactionID = '%i', \
Name = '%s',\
Owner = '%s',\
Value = '%d',\
LocationX = '%f',\
LocationY = '%f',\
LocationZ = '%f'\
WHERE FactionID = '%i'",
FInfo[i][FactionID],
FInfo[i][Name],
FInfo[i][Owner],
FInfo[i][Value],
FInfo[i][LocationX],
FInfo[i][LocationY],
FInfo[i][LocationZ],
FInfo[i][FactionID]);
mysql_query(query);
}
}
new i = 0;
while(mysql_fetch_row_format(Query, "|"))
{
// Put data into array (index i)
i ++;
}
Set i to 0 before the loop and increment in the loop.
pawn Код:
Hopefully you get the idea, and as he pointed out, MySQL is very powerful and allows you to select a lot of data at once. |
forward LoadFactions();
public LoadFactions()
{
new
Query[300],
string[128],
FactionCount;
mysql_query("SELECT * FROM Factions");
mysql_store_result();
while(mysql_fetch_row_format(Query, "|"))
{
sscanf(Query, "e<p<|>is[128]s[128]dfff>", FInfo[i]);
format(string,sizeof(string),"Faction Name: %s \nOwned by: %s\nFaction Value: %d", FInfo[i][Name], FInfo[i][Owner], FInfo[i][Value]);
CreateDynamicPickup(1239, 1, FInfo[i][LocationX], FInfo[i][LocationY], FInfo[i][LocationZ], -1, -1, -1, 100.0);
CreateDynamic3DTextLabel(string, COLOR_RED, FInfo[i][LocationX], FInfo[i][LocationY], FInfo[i][LocationZ], 100.0);
FactionCount++;
}
mysql_free_result();
return FactionCount;
}
forward LoadFactions();
public LoadFactions()
{
new
Query[300],
string[128],
FactionCount;
mysql_query("SELECT * FROM Factions");
mysql_store_result();
new i = 0;
while(mysql_fetch_row_format(Query, "|"))
{
sscanf(Query, "e<p<|>is[128]s[128]dfff>", FInfo[i]);
format(string,sizeof(string),"Faction Name: %s \nOwned by: %s\nFaction Value: %d", FInfo[i][Name], FInfo[i][Owner], FInfo[i][Value]);
CreateDynamicPickup(1239, 1, FInfo[i][LocationX], FInfo[i][LocationY], FInfo[i][LocationZ], -1, -1, -1, 100.0);
CreateDynamic3DTextLabel(string, COLOR_RED, FInfo[i][LocationX], FInfo[i][LocationY], FInfo[i][LocationZ], 100.0);
FactionCount++;
i++;
}
mysql_free_result();
return FactionCount;
}
forward SaveFactions();
public SaveFactions()
{
new query[1024];
for(new i = 0; i < FactionCount; i++)
{
format(query, sizeof(query), "UPDATE Factions SET \
Name = '%s',\
Owner = '%s',\
Value = '%d',\
LocationX = '%f',\
LocationY = '%f',\
LocationZ = '%f'\
WHERE FactionID = '%i'",
FInfo[i][Name],
FInfo[i][Owner],
FInfo[i][Value],
FInfo[i][LocationX],
FInfo[i][LocationY],
FInfo[i][LocationZ],
FInfo[i][FactionID]);
mysql_query(query);
}
}
forward SaveFaction(i);
public SaveFaction(i)
{
new query[1024];
format(query, sizeof(query), "UPDATE Factions SET \
Name = '%s',\
Owner = '%s',\
Value = '%d',\
LocationX = '%f',\
LocationY = '%f',\
LocationZ = '%f'\
WHERE FactionID = '%i'",
FInfo[i][Name],
FInfo[i][Owner],
FInfo[i][Value],
FInfo[i][LocationX],
FInfo[i][LocationY],
FInfo[i][LocationZ],
FInfo[i][FactionID]);
mysql_query(query);
}