Raised This Month: $ Target: $400
 0% 

Getting user place from mysql


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
reinert
Veteran Member
Join Date: Feb 2007
Old 04-23-2011 , 09:23   Getting user place from mysql
Reply With Quote #1

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 */;

reinert is offline
Old 04-26-2011, 09:06
reinert
This message has been deleted by Exolent[jNr]. Reason: Don't bump until 2 weeks have passed since last post.
SonicSonedit
Veteran Member
Join Date: Nov 2008
Location: Silent Hill
Old 04-26-2011 , 10:39   Re: Getting user place from mysql
Reply With Quote #2

Sort after getting it? Also you can use sql request with WHERE statement to get what you want.
__________________

SonicSonedit is offline
Sylwester
Veteran Member
Join Date: Oct 2006
Location: Poland
Old 04-26-2011 , 11:00   Re: Getting user place from mysql
Reply With Quote #3

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
__________________
Impossible is Nothing
Sylwester is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 04-26-2011 , 14:29   Re: Getting user place from mysql
Reply With Quote #4

Quote:
Originally Posted by reinert View Post
BUMP.
Don't bump until 2 weeks have passed since last post.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
reinert
Veteran Member
Join Date: Feb 2007
Old 05-08-2011 , 12:10   Re: Getting user place from mysql
Reply With Quote #5

Quote:
Originally Posted by Sylwester View Post
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 ?
reinert is offline
Sylwester
Veteran Member
Join Date: Oct 2006
Location: Poland
Old 05-08-2011 , 12:13   Re: Getting user place from mysql
Reply With Quote #6

And what's wrong with this one?
__________________
Impossible is Nothing
Sylwester is offline
reinert
Veteran Member
Join Date: Feb 2007
Old 05-08-2011 , 12:30   Re: Getting user place from mysql
Reply With Quote #7

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);


Last edited by reinert; 05-08-2011 at 12:32.
reinert is offline
Sylwester
Veteran Member
Join Date: Oct 2006
Location: Poland
Old 05-08-2011 , 12:58   Re: Getting user place from mysql
Reply With Quote #8

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

__________________
Impossible is Nothing
Sylwester is offline
reinert
Veteran Member
Join Date: Feb 2007
Old 05-08-2011 , 13:26   Re: Getting user place from mysql
Reply With Quote #9

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..
reinert is offline
Sylwester
Veteran Member
Join Date: Oct 2006
Location: Poland
Old 05-08-2011 , 13:41   Re: Getting user place from mysql
Reply With Quote #10

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.
__________________
Impossible is Nothing
Sylwester 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 19:59.


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