Formatting a query
#1

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?
Reply
#2

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

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%%'
Reply
#4

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

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


Forum Jump:


Users browsing this thread: 1 Guest(s)