Loop through table and list out players with same IP
#1

Title says it all.

I have the code below as a headstart
PHP код:
SELECT FROM accounts WHERE IP = %
Credits: a language guide app in android (SoloLearn)

I'm pretty new to mysql so I'm not sure if the code above works

Actually I'm sure the code above DOESN'T work
Reply
#2

This query is fine. It will check all the rows of the account table and show the value where the IP is whatever you mentioned. Anyway, use %e not %s since you wont require to escape the string then.
Reply
#3

Your query is fine. I wrote out an example for you:

PHP код:
stock SQL(playerid){
    
    new 
        
query[200]; 
        
    
mysql_format(MySQLquerysizeof query"SELECT * FROM accounts WHERE IP = '%e'"127.0.0.1); 
    
mysql_tquery(MySQLquery"IPAddressQuery""i"playerid);
    return 
1;

Using the '%e' specifier escapes special characters in a string for the use in a SQL statement. It prevents backslashes to the following characters: \x00, \n, \r, \, ', " and \x1a.

PHP код:
IPAddressQuery(playerid); public IPAddressQuery(playerid)
{
    if (!
cache_num_rows())
        return print(
"Accounts with that IP Address were not found.");
        
    new 
        
rString[128], rName[32]
    ; 
    
    for(new 
icache_num_rows(); i++){
        
cache_get_value(i"Name"rName);
        
        
format (rStringsizeof rString"Found '%s' with the IP address specified."rName); 
        
SendClientMessage(playerid, -1rString);
    }
        
    return 
1;

cache_num_rows() returns the number of rows found in the query.

We loop through the rows in the instance there are more than one account associated with the IP.
Reply
#4

Thanks!

EDIT: I can't give both of you rep's since I've given both of you reps recently, sorry bout that. Again, thanks!
Reply
#5

I'm using mySQL R39(avoiding cache's as much as possible, don't hate me). Could you replace cache_num_rows and cache_get_value to a R39 mode of function?
Reply
#6

Since you're pretty much new and starting fresh, I highly recommend you to use SQLite instead. It's built in the package and you don't have to set up anything but start coding, it's also somewhat easier to work with, in my personal opinion.
Reply
#7

I've gone a long way from mySQL in the script. Might take long to revise it.
Reply
#8

wiki.sa-mp.com/wiki/MySQL/R33

MysqlR39 is also the same with R33 Read through this
Reply
#9

Does
Код:
cache_get_value(i, "Name", rName); //R40
work just like

Код:
cache_get_field_content(i, "Name", rName); //R39
Reply


Forum Jump:


Users browsing this thread: 5 Guest(s)