AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   SQL fetch an array (https://forums.alliedmods.net/showthread.php?t=90147)

daanlz2 04-14-2009 14:55

SQL fetch an array
 
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?

Styles 04-14-2009 15:27

Re: SQL fetch an array
 
This looks totally wrong and will probabaly cause errors, hangs ect.. but non the less.... new irc_hosts[][] = {var, var1, var2, var3}

daanlz2 04-14-2009 15:31

Re: SQL fetch an array
 
Could you push me a bit in the right way then?


All times are GMT -4. The time now is 02:20.

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