Raised This Month: $ Target: $400
 0% 

Wrong data loading from SQL


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
Backstabnoob
BANNED
Join Date: Feb 2009
Location: Iwotadai Dorm
Old 07-15-2010 , 06:56   Wrong data loading from SQL
Reply With Quote #1

Hi there. What's wrong with the code below? I don't know why, but somehow "Aid" is anywhere 0, even though in the table it is for example 5. The admin nickname getting should work, as long as it's showing fine in the log. It's equal to "nickname" in the table. Thank's in advance.


PHP Code:
/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <sqlx>
#include <amxbans_core>


new Handleg_SqlTuple
new g_Cache[1024]

public 
plugin_init()
{
    
register_plugin("Admin Online Time""0.1""IdiotStrike")
    
    new 
Host[64],User[64],Pass[64],Db[64]
    
    
get_cvar_string("amx_sql_host",Host,63)
    
get_cvar_string("amx_sql_user",User,63)
    
get_cvar_string("amx_sql_pass",Pass,63)
    
get_cvar_string("amx_sql_db",Db,63)
    
    
g_SqlTuple SQL_MakeDbTuple(Host,User,Pass,Db)
}

public 
amxbans_admin_disconnect(id)
{
    new 
nick[36]
    
amxbans_get_admin_nick(idnick35)
    
    new 
Time get_user_time(id1)    
    
    new 
iData[1]

    
iData[0] = Time
    
    
    formatex
(g_Cache1023"SELECT * from amxnew_amxadmins where nickname LIKE '%%s%'"nick)
    
SQL_ThreadQuery(g_SqlTuple"Select"g_CacheiData2)
    
    
log_to_file("testing.log""Admin odpojen: %s; Time = %d"nickTime)
    
}

public 
Select(FailStateHandle:QueryError[], ErrcodeData[], DataSize)
{
    if(
FailState == TQUERY_CONNECT_FAILED)
        return 
set_fail_state("Could not connect to SQL database.")
    else if(
FailState == TQUERY_QUERY_FAILED)
        return 
log_amx("Query failed")
   
    if(
Errcode)
        return 
log_amx("Query failed")
        
    new 
Time Data[0]
    new 
Aid
    
    
while(SQL_MoreResults(Query))
        
Aid SQL_ReadResult(Query0)
    
    
log_to_file("testing.log""Nactena data: %d; Time = %d"AidTime)
    
    
    new 
TheData[2]
    
TheData[0] = Aid
    TheData
[1] = Time
    
    SaveAdmin
(TheData)

    return 
PLUGIN_CONTINUE
}
    

public 
SaveAdmin(iData[2])
{
    
    new 
Aid iData[0]
    new 
Time iData[1]
    
    
formatex(g_Cache1023"INSERT INTO amxnew_onlinetime VALUES ('%d', '%d', '%d') ON DUPLICATE KEY UPDATE admin_time=admin_time+%d"Aid ,Timeget_systime(), Time
    
SQL_ThreadQuery(g_SqlTuple"Handler"g_Cache)
    
    
log_to_file("testing.log""Snazim se ulozit informace admina: %d; Time = %d"AidTime)
    
}

public 
Handler(FailStateHandle:QueryError[], ErrcodeData[], DataSize)
{
    if(
FailState == TQUERY_CONNECT_FAILED)
        return 
set_fail_state("Could not connect to SQL database.")
    else if(
FailState == TQUERY_QUERY_FAILED)
        return 
log_amx("Query failed")
   
    if(
Errcode)
        return 
log_amx("Query failed")
        
    
log_to_file("testing.log""Uspesne ulozeno.")
    
    return 
PLUGIN_CONTINUE

Edit: oh and yeah, in amxnew_amxadmins id is the first column, so Aid = SQL_ReadResult(Query, 0) should load it just fine. I think there is something wrong with that " where nickname LIKE "%%s%" ", but I'm not sure.

Edit2: where nickname='%s' doesn't work either - still returns 0 in Aid

Last edited by Backstabnoob; 07-15-2010 at 07:00.
Backstabnoob is offline
 


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 07:09.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode