how to load strings from mysql?
#1

thats my question.
Reply
#2

Show your code first.
Reply
#3

Код:
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
Reply
#4

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];
Reply
#5

i didnt get you. i just removed strval and it says it should be assigned to an array
Reply
#6

Use this:
Quote:

format(oname[playerid], 24, "%s" field[1]);
format(ocolour[playerid], 10, "%s" field[2]);

Reply
#7

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.
Reply
#8

doesnt work =(
Reply
#9

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);
Reply
#10

no luck
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)