SA-MP Forums Archive
Formatting a query - 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)
+--- Thread: Formatting a query (/showthread.php?tid=616311)



Formatting a query - biker122 - 03.09.2016

Hey, I've ran into a small problem which I can't figure out why it happens..
I want to fetch all the accounts under a given IP range, and I've scripted the necessary things for it. When I format the query, it leaves the range format (%..%).
1. I used this code:
pawn Код:
format(gQuery, sizeof gQuery, "SELECT `Username`, `IP` FROM `"Users_Table"` WHERE `IP` LIKE '%%s%'", inputtext);
The inputtext was 127.0. and it printed "127.0." and not %127.0.%
2. I used this code:
pawn Код:
new ip[18];
format(ip, sizeof ip, "%s", inputtext);
format(gQuery, sizeof gQuery, "SELECT `Username`, `IP` FROM `"Users_Table"` WHERE `IP` LIKE %'%s'%", ip);
The inputtext was 127.0. and it printed "127.0.%" in the console (% = #, in console)

Am I doing something wrong, or isn't that the way to use such query?


Re: Formatting a query - Stinged - 03.09.2016

Two % inserts an actual '%', so it should be:
Код:
'%%%s%'



Re: Formatting a query - jlalt - 03.09.2016

Quote:
Originally Posted by Stinged
Посмотреть сообщение
Two % inserts an actual '%', so it should be:
Код:
'%%%s%'
I'm pretty sure you have to add one more % in last.

so it gotta be
Код:
'%%%s%%'



Re: Formatting a query - Stinged - 03.09.2016

Quote:
Originally Posted by jlalt
Посмотреть сообщение
I'm pretty sure you have to add one more % in last.

so it gotta be
Код:
'%%%s%%'
Oh yes sorry, I was trying it out before with the last % being that actual last character in the string.
As long as there's something after the %, it needs to be two.


Re: Formatting a query - biker122 - 03.09.2016

Thank you, Stinged and jlalt! Jlalt's code worked fine, and it printed "%ipaddress%", what I wanted. (+rep to both of you)