MySQL question
#1

Hello.
I have a table called user which stores all ip's etcetra.
I also have a table called adminlogs, which stores all previous bans.
I am making a offline ban command, so it needs to get the IP from the table called user, and then use it
in the creation of the table adminlogs.

now the big question;
How do i do this?
Reply
#2

PHP код:
mysql_format(dbquerysizeof(query), "SELECT `IP` FROM `users` WHERE `Username` = BINARY('%s') LIMIT 1"GetpName(playerid)); //selects IP from `users`
mysql_pquery(dbquery"AdminLogs""d"playerid); 
somewhere at the bottom of your script:
PHP код:
forward AdminLogs(playerid);
public 
AdminLogs(playerid)
{
    
//do whatever you want with that IP
    
return 1;

Reply
#3

Quote:
Originally Posted by luke49
Посмотреть сообщение
PHP код:
mysql_format(dbquerysizeof(query), "SELECT `IP` FROM `users` WHERE `Username` = BINARY('%s') LIMIT 1"GetpName(playerid)); //selects IP from `users`
mysql_pquery(dbquery"AdminLogs""d"playerid); 
somewhere at the bottom of your script:
PHP код:
forward AdminLogs(playerid);
public 
AdminLogs(playerid)
{
    
//do whatever you want with that IP
    
return 1;

so far i got this:
PHP код:
COMMAND:osuspend(playeridparams[])
{
 if(!
PlayerInfo[playerid][power]) return SendClientError(playeridCANT_USE_CMD);
    new 
iPlayer[40], eReason128 ];
    if(
sscanf(params,"ss"iPlayereReason))  return SCP(playerid"[Exact_Name] [Reason]");
new 
query3[128];
    
format(query3,sizeof(query3),"SELECT * FROM user WHERE username ='%s'",iPlayer);
    
mysql_function_query(dbhandle,query3,true,"OnSuspend","iss",playerid,eReason,iPlayer);
    return 
1;

PHP код:
forward OnSuspend(playerid,eReason,iPlayer);
public 
OnSuspend(playerid,eReason,iPlayer)
{
        
// get the cache data and do whatever other needed operations
    
new num_rows,num_fields;
    
cache_get_data(num_rows,num_fields,dbhandle);
    new 
query[400],query2[400],string2[128],messaggio[MAX_STRING], string[MAX_STRING],query3[128],temp_ip[32],temp_gpci[100],string6[32],string5[60];
    
format(query,sizeof(query),"INSERT INTO suspended (username,reason,bannedby,whendidithappen) VALUES ('%s','%s','%s','%s')",iPlayer,eReason,AnonAdmin(playerid),TimeDate());
    
mysql_function_query(dbhandle,query,false,"","");
    
format(messaggio,sizeof(messaggio),"{FF0000}[Admin]{FF6347} %s has offline-suspended %s. Reason: %s",AnonAdmin(playerid),iPlayer,eReason);
    
format(string,sizeof(string), "4{ OSUSPEND } %s[%d] has offline-suspended %s. Reason: %s %s",AnonAdmin(playerid), playeridiPlayer,  eReasonTimeDate());
    
format(string2,sizeof(string2),"[OSUSPEND] By %s for %s",AnonAdmin(playerid),eReason);
    
format(query3,sizeof(query3),"SELECT * FROM user WHERE username ='%s'",iPlayer);
    
mysql_function_query(dbhandle,query3,true,"","");
    
cache_get_field_content(0"regip"temp_ip);
    
format(string6,sizeof(string6),"%s",temp_ip);
    
cache_get_field_content(0"reggpci"temp_gpci);
    
format(string5,sizeof(string5),"%s",temp_gpci);
       
format(query2,sizeof(query2),"INSERT INTO adminlogs (username,bywho,wat,whendidithappen,ip,gpci) VALUES ('%s','%s','%s','%s','%s','%s')",iPlayer,AnonAdmin(playerid),string2,TimeDate(),string6,string5);
    
mysql_function_query(dbhandle,query2,false,"","");
       
SendMessageToAll(COLOR_RED,messaggio);
       
iEcho(string);
        return 
true;

It all does the job good, thanks.
Only 1 thing: iPlayer now gets defined as "Ь" according to my database.
Any idea why that is?

same goes for the reason
Reply
#4

pawn Код:
INSERT INTO `adminlog` (`Ip`) SELECT `Ip` FROM `user` WHERE `Username` = 'something';
This will insert a new row into `adminlog` table and the row will contain the `Ip` address extracted from the `user` table, the filter applied for user table is `Username` = 'something' (can be anything according to your code).

This is a direct query. You may modify it according to your needs.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)