30.09.2011, 04:59
Hello,
Im having some issues trying to figure out foreach. Im trying to pull some rows from a MySQL database, throw all of the information into an IteratorArray and get a random one. So far, its not going too well. Heres my code.
Help, ideas? Anything is appreciated
Im having some issues trying to figure out foreach. Im trying to pull some rows from a MySQL database, throw all of the information into an IteratorArray and get a random one. So far, its not going too well. Heres my code.
pawn Code:
stock LoadMission(playerid)
{
new parea[28], qry[128], IteratorArray:missions[250]<7>;
GetPlayer3DZone2(playerid, parea, sizeof(parea));
format(qry, sizeof(qry), "SELECT * FROM locations WHERE lType = 1 OR lType = 3 AND lArea = '%s'", parea);
mysql_query(qry);
mysql_store_result();
new row[128], tmp[128], lid;
Iter_Init(missions);
while(mysql_fetch_row(row))
{
mysql_get_field("lX", tmp);
Iter_Add(lid, tmp);
mysql_get_field("lY", tmp);
Iter_Add(lid, tmp);
mysql_get_field("lZ", tmp);
Iter_Add(lid, tmp);
mysql_get_field("lName", tmp);
Iter_Add(lid, tmp);
mysql_get_field("lZone", tmp);
Iter_Add(lid, tmp);
mysql_get_field("lArea", tmp);
Iter_Add(lid, tmp);
mysql_get_field("lType", tmp);
Iter_Add(lid, tmp);
lid++;
}
new worktd[256], missionsloaded;
foreach(lid, missionsloaded)
{
new msg[128], mission;
format(msg, sizeof(msg), "Loaded mission number %d", Iter_Random(missions));
SendClientMessage(playerid, COLOR_SEAGREENTWO, msg);
}
}