how to load strings from mysql? - 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)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: how to load strings from mysql? (
/showthread.php?tid=220401)
how to load strings from mysql? -
THE_KNOWN - 03.02.2011
thats my question.
Re: how to load strings from mysql? -
DVDK - 03.02.2011
Show your code first.
Re: how to load strings from mysql? -
THE_KNOWN - 03.02.2011
Код:
LoadOstats(playerid)
{
new name[MAX_PLAYER_NAME];
GetPlayerName(playerid, name, sizeof(name));
new query[128];
format(query, sizeof(query), "SELECT * FROM ostats WHERE name='%s'", name);
mysql_query(query);
mysql_store_result();
new row[128];
new field[13][32];
mysql_fetch_row_format(row, "|");
explode(row, field, "|");
org[playerid] =strval(field[1]);
leader[playerid]=strval(field[3]);
req[playerid]=strval(field[2]);
mysql_free_result();
new string[128];
format(string, sizeof(string), "SELECT * FROM orgs WHERE ID=%d", org[playerid]);
mysql_query(string);
mysql_store_result();
mysql_fetch_row_format(row, "|");
explode(row, field, "|");
oname[playerid]=strval(field[1]);
ocolour[playerid]=strval(field[2]);
otype[playerid]=strval(field[3]);
oskin[playerid]=strval(field[4]);
oskin1[playerid]=strval(field[5]);
oskin2[playerid]=strval(field[6]);
mysql_free_result();
return 1;
}
need it for oname and ocolour
Re: how to load strings from mysql? -
JaTochNietDan - 03.02.2011
Then you simply make sure that the variables you've created called "oname" and "ocolour" are multi-dimensional arrays with at least 32 cells in the second dimension, otherwise the Pawn compiler will throw you an error because the "field" array has more cells, then you simply don't use strval, as that's used for getting the value of a string, which you don't want to do:
pawn Код:
oname[playerid] = field[1];
ocolour[playerid] = field[2];
Re: how to load strings from mysql? -
THE_KNOWN - 03.02.2011
i didnt get you. i just removed strval and it says it should be assigned to an array
Re: how to load strings from mysql? -
DVDK - 03.02.2011
Use this:
Quote:
format(oname[playerid], 24, "%s" field[1]);
format(ocolour[playerid], 10, "%s" field[2]);
|
Re: how to load strings from mysql? -
JaTochNietDan - 03.02.2011
Quote:
Originally Posted by THE_KNOWN
i didnt get you. i just removed strval and it says it should be assigned to an array
|
Well that error would suggest that you didn't even make those variables an array, so how are they going to store the string as one character takes up each cell!
You need to initialize the arrays with enough cells to hold the information.
For example:
pawn Код:
new oname[MAX_PLAYERS][24];
DVDK's fix will not work unless you have initialized them as a multi-dimensional array either.
Re: how to load strings from mysql? -
THE_KNOWN - 04.02.2011
doesnt work =(
Re: how to load strings from mysql? -
PeteShag - 04.02.2011
pawn Код:
strmid([playerid]oname, field[1], 0, strlen(field[1]), 255);
strmid([playerid]ocolour, field[2], 0, strlen(field[2]), 255);
or
pawn Код:
strmid(oname[playerid], field[1], 0, strlen(field[1]), 255);
strmid(ocolour[playerid], field[2], 0, strlen(field[2]), 255);
Re: how to load strings from mysql? -
THE_KNOWN - 04.02.2011
no luck