AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Getting user place from mysql (https://forums.alliedmods.net/showthread.php?t=155525)

reinert 04-23-2011 09:23

Getting user place from mysql
 
So how can I get the users place from mysql, by skill descending.

I've got table like:

UserAuth__Skill
:1:61561___215
:0:47005___57
:1:99824___532

PHP Code:

get_user_rank(id)
{
     return 
/* what here */;



SonicSonedit 04-26-2011 10:39

Re: Getting user place from mysql
 
Sort after getting it? Also you can use sql request with WHERE statement to get what you want.

Sylwester 04-26-2011 11:00

Re: Getting user place from mysql
 
You can do it with something like this:
PHP Code:

new sql_table[] = "table_name"
new authid[32]
get_user_authid(idauthid31)
new 
cache[512]

fornatex(cache511"SELECT COUNT(*)+1 AS rank FROM %s WHERE Skill>(SELECT Skill FROM %s WHERE UserAuth=%s);"sql_tablesql_tableauthid


Exolent[jNr] 04-26-2011 14:29

Re: Getting user place from mysql
 
Quote:

Originally Posted by reinert (Post 1458178)
BUMP.

Don't bump until 2 weeks have passed since last post.

reinert 05-08-2011 12:10

Re: Getting user place from mysql
 
Quote:

Originally Posted by Sylwester (Post 1458245)
You can do it with something like this:
PHP Code:

new sql_table[] = "table_name"
new authid[32]
get_user_authid(idauthid31)
new 
cache[512]

fornatex(cache511"SELECT COUNT(*)+1 AS rank FROM %s WHERE Skill>(SELECT Skill FROM %s WHERE UserAuth=%s);"sql_tablesql_tableauthid


Maybe any another method ?

Sylwester 05-08-2011 12:13

Re: Getting user place from mysql
 
And what's wrong with this one?

reinert 05-08-2011 12:30

Re: Getting user place from mysql
 
Actually I don't know how to use it properly.

I don't know how to print the result with client_print.

Like: Your rank is %d of %d.
Right now I've got this:
PHP Code:

public CmdRank(id)
{
    new 
szTemp[512];
    new 
szAuthID[33];
    
get_user_authid(idszAuthIDsizeof(szAuthID))
    
formatex(szTemp511"SELECT COUNT(*)+1 AS rank FROM rank WHERE skill>(SELECT skill FROM rank WHERE UserAuth=%s);"szAuthID)
    
SQL_ThreadQuery(g_SqlTuple,"IgnoreHandle",szTemp);



Sylwester 05-08-2011 12:58

Re: Getting user place from mysql
 
It won't work with IgnoreHandle. You need to read results like this:
PHP Code:

public CmdRank(id){
    new 
szTemp[512];
    new 
szAuthID[33];
    
get_user_authid(idszAuthIDsizeof(szAuthID))
    new 
data[1]
    
data[0] = id
    formatex
(szTemp511"SELECT COUNT(*)+1 AS rank FROM rank WHERE skill>(SELECT skill FROM rank WHERE UserAuth='%s');"szAuthID)
    
SQL_ThreadQuery(g_SqlTuple,"handle_rank",szTempdata1);


public 
handle_rank(FailState,Handle:Query,Error[],Errcode,Data[],DataSize){
    if(
FailState){
        
log_amx("SQL Error: %s (%d)"ErrorErrcode)
        return 
PLUGIN_HANDLED
    
}
    new 
id Data[0]
    if(
SQL_MoreResults(Query)){
        new 
rank SQL_ReadResult(Query,SQL_FieldNameToNum(Query,"rank"))
        
client_print(idprint_chat"Your rank is %d"rank)
    }else{
        
client_print(idprint_chat"Could not retrieve your rank")
    }
    return 
PLUGIN_HANDLED



reinert 05-08-2011 13:26

Re: Getting user place from mysql
 
One more question, How can I retrieve the line number in SQL ?
So it will be like: ....."your rank is %d out of %d", rank, MAX_LINES)

And when I write /rank, I've to wait like 2-3 seconds and only then I see the result..

Sylwester 05-08-2011 13:41

Re: Getting user place from mysql
 
To get amount of rows in table you can use.
PHP Code:

"SELECT COUNT(*) AS total FROM rank;" 

With your current code, when you write /rank, the server sends query to your sql server and needs to wait for reply, so it's obvious that you will not get results instantly.

If you want that message to appear instantly, then store rank in some veriable when user enters server and update the value in that variable when it's necessary. Then you can use that variable to display rank instantly.


All times are GMT -4. The time now is 19:59.

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