Thread: [Solved] Retrieve data from sql
View Single Post
Author Message
N3v3rM1nd
Member
Join Date: Apr 2021
Old 04-24-2024 , 09:22   Retrieve data from sql
Reply With Quote #1

Hi, could anyone help me with a piece of code for a RANK function?

For example, I have this top function:
PHP Code:
formatex(szTempcharsmax(szTemp), "SELECT * FROM `%s` ORDER BY `score` DESC LIMIT 0,15"TABEL);
SQL_ThreadQuery(g_SqlTuple"ZP_TOP"szTempszData1
PHP Code:
public ZP_TOPFailStateHandle:QueryError[], ErrcodeData[], DataSize 
{
    if(
FailState == TQUERY_CONNECT_FAILED
        
log_amx("Load - Could not connect to SQL database.  [%d] %s"ErrcodeError)
    else if(
FailState == TQUERY_QUERY_FAILED
        
log_amx("Load Query failed. [%d] %s"ErrcodeError)

    new 
idid Data[0]
    new 
to_get[15][64]
        
    new 
rows1 SQL_NumResults(Query)
    new 
iScore[15]

    if(
SQL_MoreResults(Query)) 
    {
        for(new 
rows1 i++)
        {
            
SQL_ReadResult(Query1to_get[i], 63)
            
iScore[i] = SQL_ReadResult(Query6)
            
            
SQL_NextRow(Query)
        }
    }

    if(
rows1 0
    {
        new 
iLen=0;
        
iLen formatg_Buffer[iLen], 2047g_sTopStyle )
        
iLen += formatg_Buffer[iLen], 2047 iLen"<body bgcolor=#000000><table border=0 cellspacing=0 cellpadding=3px><tr><th class=p>#<td class=p><th>Player<th>Score" )     

        for(new 
rows1 i++) 
        {
            new 
rowColor[16];
            if(
3)
            {
                if(
== 0format(rowColorsizeof(rowColor), "blue");
                else if(
== 1format(rowColorsizeof(rowColor), "yellow");
                else 
format(rowColorsizeof(rowColor), "red");
            } 
            else 
format(rowColorsizeof(rowColor), "");
            
iLen += format(g_Buffer[iLen], 2047 iLen"<tr><td class=p>%d<td class=p><td class=%s>%s<td>%i<td>"1rowColorto_get[i], iScore[i]);
        }
        
show_motd(idg_Buffer"Top15 Zombie")
    }
    return 
1

and I want to make one for RANK, and display:
"[AMXX] Your rank is m/n with a data1 b data2 c data3 d data4"
Where 'm' is the current rank of the player (or position in the DB, I'm not sure how it would come), 'n' is the total entries in the DB, and a, b, c, d are other integer values.

Last edited by N3v3rM1nd; 05-06-2024 at 10:54.
N3v3rM1nd is offline