Raised This Month: $ Target: $400
 0% 

Total Entries in MySql


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
demon81
Member
Join Date: Sep 2010
Location: Portugal
Old 08-08-2014 , 04:15   Total Entries in MySql
Reply With Quote #1

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!
demon81 is offline
SpeeDeeR
Veteran Member
Join Date: Mar 2010
Location: Bulgaria
Old 08-08-2014 , 13:33   Re: Total Entries in MySql
Reply With Quote #2

Code:
SELECT COUNT(column_name) FROM table_name;
Where 'column_name' should be your primary key.
SpeeDeeR is offline
Backstabnoob
BANNED
Join Date: Feb 2009
Location: Iwotadai Dorm
Old 08-08-2014 , 14:32   Re: Total Entries in MySql
Reply With Quote #3

Code:
SELECT COUNT(*) AS total, SUM(CASE WHEN exp >= %d THEN 1 ELSE 0 END) AS rank FROM tutorial
Backstabnoob is offline
demon81
Member
Join Date: Sep 2010
Location: Portugal
Old 08-08-2014 , 15:53   Re: Total Entries in MySql
Reply With Quote #4

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

Last edited by demon81; 08-08-2014 at 15:53.
demon81 is offline
Backstabnoob
BANNED
Join Date: Feb 2009
Location: Iwotadai Dorm
Old 08-08-2014 , 16:39   Re: Total Entries in MySql
Reply With Quote #5

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)
Backstabnoob is offline
demon81
Member
Join Date: Sep 2010
Location: Portugal
Old 08-08-2014 , 17:07   Re: Total Entries in MySql
Reply With Quote #6

but the
SQL_ReadResult(Query, 0) is already set to count the rank. can you change in the code i posted before?
demon81 is offline
aron9forever
Veteran Member
Join Date: Feb 2013
Location: Rromania
Old 08-10-2014 , 07:39   Re: Total Entries in MySql
Reply With Quote #7

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)
__________________
Meanwhile, in 2050:
Quote:
Originally Posted by aron9forever
useless small optimizations
Quote:
Originally Posted by Black Rose View Post
On a map that is 512x512x128 units you end up with 3,355,443,200,000 different "positions". To store each one of those positions individually in the variable "user_or" you need 12 terabytes of memory.

Last edited by aron9forever; 08-10-2014 at 07:40.
aron9forever is offline
Backstabnoob
BANNED
Join Date: Feb 2009
Location: Iwotadai Dorm
Old 08-10-2014 , 09:43   Re: Total Entries in MySql
Reply With Quote #8

Quote:
Originally Posted by aron9forever View Post
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?
Backstabnoob is offline
aron9forever
Veteran Member
Join Date: Feb 2013
Location: Rromania
Old 08-10-2014 , 09:52   Re: Total Entries in MySql
Reply With Quote #9

Quote:
Originally Posted by Backstabnoob View Post
Are you serious?
very, why?
__________________
Meanwhile, in 2050:
Quote:
Originally Posted by aron9forever
useless small optimizations
Quote:
Originally Posted by Black Rose View Post
On a map that is 512x512x128 units you end up with 3,355,443,200,000 different "positions". To store each one of those positions individually in the variable "user_or" you need 12 terabytes of memory.
aron9forever is offline
YamiKaitou
Has a lovely bunch of coconuts
Join Date: Apr 2006
Location: Texas
Old 08-10-2014 , 18:45   Re: Total Entries in MySql
Reply With Quote #10

Quote:
Originally Posted by aron9forever View Post
very, why?
Because if you want to count the number of rows returned in the result, you should be using SQL_NumResults
__________________
ProjectYami Laboratories

I do not browse the forums regularly anymore. If you need me for anything (asking questions or anything else), then PM me (be descriptive in your PM, message containing only a link to a thread will be ignored).
YamiKaitou is offline
Reply


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 13:00.


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