AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Total Entries in MySql (https://forums.alliedmods.net/showthread.php?t=245868)

demon81 08-08-2014 04:15

Total Entries in MySql
 
Code:

public Show_Rank(id) // register cmd to this function
{
    for(new
i; i < MaxPlayers; i++)
    {
        if(
is_user_connected(i))
         
Save_MySql(i) // Save all stats to get the correct rank
   
}
       
    new
Data[1]
   
Data[0] = id
   
   
new szTemp[512]
   
format(szTemp,charsmax(szTemp),"SELECT COUNT(*) FROM `tutorial` WHERE `exp` >= %d", Exp[id])
   
// Select the count where the exp is matching or higher (Incase of equal exp)
   
SQL_ThreadQuery(g_SqlTuple,"Sql_Rank",szTemp,Data,1)
       
    return
PLUGIN_CONTINUE
}

public
Sql_Rank(FailState,Handle:Query,Error[],Errcode,Data[],DataSize)
{
    if(
FailState == TQUERY_CONNECT_FAILED)
           
log_amx("Load - Could not connect to SQL database.  [%d] %s", Errcode, Error)
    else if(
FailState == TQUERY_QUERY_FAILED)
           
log_amx("Load Query failed. [%d] %s", Errcode, Error)
 
    new
count = 0
    count
= SQL_ReadResult(Query,0)
    if(
count == 0)
   
count = 1
   
   
new id
    id
= Data[0]

   
client_print(id, print_chat, "You are at rank %i with %i exp", count, Exp[id]);
   
    return
PLUGIN_HANDLED
}



how do i get the total entries to make it show like this:

"You are at rank %i from %i with %i exp" being the second "%i" the total entries/players.

Thanks in advance!

SpeeDeeR 08-08-2014 13:33

Re: Total Entries in MySql
 
Code:

SELECT COUNT(column_name) FROM table_name;
Where 'column_name' should be your primary key.

Backstabnoob 08-08-2014 14:32

Re: Total Entries in MySql
 
Code:

SELECT COUNT(*) AS total, SUM(CASE WHEN exp >= %d THEN 1 ELSE 0 END) AS rank FROM tutorial

demon81 08-08-2014 15:53

Re: Total Entries in MySql
 
and how do i make it appearing in the chat?
like this?
Code:

format(szTemp,charsmax(szTemp),"SELECT COUNT(*) AS total, SUM(CASE WHEN exp >= %d THEN 1 ELSE 0 END) AS rank FROM tutorial", total[id])
and then

Code:

client_print(id, print_chat, "You are at rank %i from %i with %i exp", count, total[id], Exp[id]);
?

because i have tried and it doesn't work :(

Backstabnoob 08-08-2014 16:39

Re: Total Entries in MySql
 
What doesn't work? It's not total[id]. That should be Exp[id] like you had it before.

You need to use
new TotalPlayers = SQL_ReadResult(Query, 0)
new Rank = SQL_ReadResult(Query, 1)

demon81 08-08-2014 17:07

Re: Total Entries in MySql
 
but the
SQL_ReadResult(Query, 0) is already set to count the rank. can you change in the code i posted before?

aron9forever 08-10-2014 07:39

Re: Total Entries in MySql
 
you could always also
PHP Code:

new count
while(SQL_MoreResults(Query))
        {
            
count++
            
SQL_NextRow(Query)
        } 

if you don't wanna do it the sql way
you can use the same query you used to get the rank, but without the name / steamid / ip condition at the end(WHERE xxxxx)

Backstabnoob 08-10-2014 09:43

Re: Total Entries in MySql
 
Quote:

Originally Posted by aron9forever (Post 2181970)
you could always also
PHP Code:

new count
while(SQL_MoreResults(Query))
        {
            
count++
            
SQL_NextRow(Query)
        } 

if you don't wanna do it the sql way
you can use the same query you used to get the rank, but without the name / steamid / ip condition at the end(WHERE xxxxx)

Are you serious?

aron9forever 08-10-2014 09:52

Re: Total Entries in MySql
 
Quote:

Originally Posted by Backstabnoob (Post 2182027)
Are you serious?

very, why? :fox:

YamiKaitou 08-10-2014 18:45

Re: Total Entries in MySql
 
Quote:

Originally Posted by aron9forever (Post 2182035)
very, why? :fox:

Because if you want to count the number of rows returned in the result, you should be using SQL_NumResults


All times are GMT -4. The time now is 13:00.

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