Raised This Month: $ Target: $400
 0% 

SQL fetch an array


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
daanlz2
Junior Member
Join Date: Sep 2008
Old 04-14-2009 , 14:55   SQL fetch an array
Reply With Quote #1

Hi Allied modders,

Im a bit new to amxx scripting and im wondering if someone could help me:

Code:
new error[128], errno
new i = 0

new Handle:info = SQL_MakeStdTuple()
new Handle:sql = SQL_Connect(info, errno, error, 127)
new Handle:query = SQL_PrepareQuery(sql, "SELECT * FROM `%s` ", table)
if (!SQL_Execute(query))
    {
        SQL_QueryError(query, error, 127)
        server_print("[AMXX] %L", LANG_SERVER, "SQL_CANT_LOAD_ADMINS", error)
    } else if (!SQL_NumResults(query)) {
        server_print("[AMXX] %L", LANG_SERVER, "NO_ADMINS")
    } else {
    
    new long = SQL_NumResults (sql, "SELECT * FROM `%s` ", table)) 
    
    new irc_hosts[long]
    new irc_names[long]
    new irc_flags[long]
    new irc_steamids[long]
    
    
        new qircauth = SQL_FieldNameToNum(query, "ircauth")
        new qnickname = SQL_FieldNameToNum(query, "nickname")
        new qaccess = SQL_FieldNameToNum(query, "access")
        new qsteamid = SQL_FieldNameToNum(query, "steamid")

        i = 0        

        while (SQL_MoreResults(query))
        {
            SQL_ReadResult(query, qircauth , qircauth[i], 31)
            SQL_ReadResult(query, qircauth , qnickname[i], 31)
            SQL_ReadResult(query, qircauth , qaccess[i], 31)
            SQL_ReadResult(query, qircauth , qsteamid[i], 31)

            irc_hosts[i] = qircauth[i]
            irc_names[i] = qnickname[i]
            irc_flags[i] = qaccess[i]
            irc_steamids[i] = qsteamid[i]
    
            ++i

            SQL_NextRow(query)

        }
    }

    if (i == 1)
            server_print("[AMXX] %L", LANG_SERVER, "SQL_LOADED_ADMIN")
        else
            server_print("[AMXX] %L", LANG_SERVER, "SQL_LOADED_ADMINS", i)
        
        SQL_FreeHandle(query)
        SQL_FreeHandle(sql)
        SQL_FreeHandle(info)
    }



}
i need to get the information from the mysql database into an array like this:

Code:
new irc_hosts[][] = "host1","host2" etc..
Who can push me a bit in the right way?
daanlz2 is offline
 



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 02:20.


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