SA-MP Forums Archive
Loop through table and list out players with same IP - 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: Loop through table and list out players with same IP (/showthread.php?tid=647184)



Loop through table and list out players with same IP - NealPeteros - 31.12.2017

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


Re: Loop through table and list out players with same IP - Ritzy2K - 31.12.2017

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.


Re: Loop through table and list out players with same IP - Kane - 31.12.2017

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.


Re: Loop through table and list out players with same IP - NealPeteros - 31.12.2017

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!


Re: Loop through table and list out players with same IP - NealPeteros - 31.12.2017

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?


Re: Loop through table and list out players with same IP - Beckett - 31.12.2017

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.


Re: Loop through table and list out players with same IP - NealPeteros - 31.12.2017

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


Re: Loop through table and list out players with same IP - JesterlJoker - 31.12.2017

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

MysqlR39 is also the same with R33 Read through this


Re: Loop through table and list out players with same IP - NealPeteros - 31.12.2017

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

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