SA-MP Forums Archive
Text string (urgent :<) - 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: Text string (urgent :<) (/showthread.php?tid=198905)



Text string (urgent :<) - hanzen - 13.12.2010

Hello

I'm trying to retrieve a textstring from my MySQL database. Haven't really found a good way to do this, (well it always fucks up). This is it:
Код:
		new tdata[255], Float:tx, Float:ty, Float:tz, desc;
		format(query, sizeof(query), "SELECT * FROM `teleports` WHERE `para` = '%s';", tmp);
		mysql_query(query); mysql_store_result();
		
		mysql_fetch_field("x", tdata); tx = floatstr(tdata);
		mysql_fetch_field("y", tdata); ty = floatstr(tdata);
		mysql_fetch_field("z", tdata); tz = floatstr(tdata);
		mysql_fetch_field("desc", tdata); strmid(desc, tdata, 0, strlen(tdata), 255);
This only returns me the error:
Код:
D:\Prosjekter\HD-RP\gamemodes\hd-rp.pwn(400) : error 035: argument type mismatch (argument 1)
Does anyone know how to retrieve it? It's a varchar.

Would really appreciate answers, really!


Re: Text string (urgent :<) - Ash. - 13.12.2010

Which line is "line 400"


Re: Text string (urgent :<) - hanzen - 13.12.2010

mysql_fetch_field("desc", tdata); strmid(desc, tdata, 0, strlen(tdata), 255);


Re: Text string (urgent :<) - hanzen - 13.12.2010

Really? Such a "easy" thing and no-one knows? Should it be that hard to withdraw a text-string from mysql? grr


Re: Text string (urgent :<) - Benjo - 13.12.2010

The error that you are getting refers to the strmid function. Here are the parameters for it:
pawn Код:
strmid(dest[],const source[],start,end,maxlength=sizeof dest)
You are getting the error because you have not defined your variable "desc" as an array. Try this:
pawn Код:
new tdata[255], Float:tx, Float:ty, Float:tz, desc[255];
format(query, sizeof(query), "SELECT * FROM `teleports` WHERE `para` = '%s';", tmp);
mysql_query(query); mysql_store_result();
       
mysql_fetch_field("x", tdata); tx = floatstr(tdata);
mysql_fetch_field("y", tdata); ty = floatstr(tdata);
mysql_fetch_field("z", tdata); tz = floatstr(tdata);
mysql_fetch_field("desc", tdata); strmid(desc, tdata, 0, strlen(tdata), 255);
Note that you may not need to use array sizes of 255; use a lower value if possible to improve on performance. Good luck!

EDIT:

For a VARCHAR field (ie your "desc" field) you can just store it direct like this:
pawn Код:
new tdata[255], Float:tx, Float:ty, Float:tz, desc[255];
format(query, sizeof(query), "SELECT * FROM `teleports` WHERE `para` = '%s';", tmp);
mysql_query(query); mysql_store_result();

mysql_fetch_field("x", tdata); tx = floatstr(tdata);
mysql_fetch_field("y", tdata); ty = floatstr(tdata);
mysql_fetch_field("z", tdata); tz = floatstr(tdata);
mysql_fetch_field("desc", desc);



Re: Text string (urgent :<) - hanzen - 13.12.2010

THANKS! worked great