Raised This Month: $ Target: $400
 0% 

top10 mysql Problem


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Stylaa
Senior Member
Join Date: Oct 2009
Location: Flensburg, Germany
Old 10-23-2010 , 11:11   top10 mysql Problem
Reply With Quote #1

got an error it displays on all names 48 Kills and dont shows the best 15

How to fix?

PHP Code:

    
public ShowTop10(id) {
    
    new 
szTemp[512]
    static 
Data[2]
    
    
Data[0] = id

    format
(szTemp,charsmax(szTemp),"SELECT * FROM stats ORDER BY points ASC LIMIT 10")
    
SQL_ThreadQuery(g_SqlTuple,"displaytop10",szTemp,Data,2)
    
}


public 
displaytop10(FailState,Handle:Query,Error[],Errcode,Data[],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 
id
    id 
Data[0]
    
        
    if(!
SQL_MoreResults(Query)) {
        
        
        return 
1
    
}
    
    
    static 
Name[33], PlacePoints[33]
    
    
Place 0
    
    
new MenuBody[512], lenkeys;
    
    
len format(MenuBody511"\yStats TOP 10 \r[Version: \y%s\r]^n"VERSION);
    
    while(
SQL_MoreResults(Query)) {
        
        
Place++
        
        
SQL_ReadResult(Query,7,Name,32)
        
        
SQL_ReadResult(Query,1,Points,32)
        
        
len += format(MenuBody[len], 511-len"^n\r%d. %s %d Kills"PlaceNamePoints);
        
        
SQL_NextRow(Query)
    }

    
    
keys = ( 1<<1<<1<<);
    
    if( 
get_user_flags(id) & ADMIN_USER 
    
keys |= ( 1<<1<<1<<1<<1<<1<<);

    
show_menu(idkeysMenuBody, -1"StatsMenu");
    
    return 
0

__________________

Some People brings Happynes by Coming
Some by Going
Stylaa is offline
Send a message via ICQ to Stylaa
Sylwester
Veteran Member
Join Date: Oct 2006
Location: Poland
Old 10-23-2010 , 11:40   Re: top10 mysql Problem
Reply With Quote #2

Post stats table definition.
__________________
Impossible is Nothing
Sylwester is offline
Stylaa
Senior Member
Join Date: Oct 2009
Location: Flensburg, Germany
Old 10-23-2010 , 13:51   Re: top10 mysql Problem
Reply With Quote #3

1. is Steamid
2. is Kills and in the
8th the PLayrnick
beetween 3 - 7 are ct kills t kills and some other thinks
__________________

Some People brings Happynes by Coming
Some by Going
Stylaa is offline
Send a message via ICQ to Stylaa
Sylwester
Veteran Member
Join Date: Oct 2006
Location: Poland
Old 10-23-2010 , 13:58   Re: top10 mysql Problem
Reply With Quote #4

I want to see exact statement ("CREATE TABLE ...") with data types, not description.
__________________
Impossible is Nothing
Sylwester is offline
Stylaa
Senior Member
Join Date: Oct 2009
Location: Flensburg, Germany
Old 10-23-2010 , 14:02   Re: top10 mysql Problem
Reply With Quote #5

PHP Code:
CREATE TABLE IF NOT EXISTS stats (steamid varchar(32),points INT(11),killedcts INT(11),secounds INT(11),pissed INT(11),terrorskilled INT(11),zombiskilled INT(11),name varchar(32)) 
__________________

Some People brings Happynes by Coming
Some by Going
Stylaa is offline
Send a message via ICQ to Stylaa
Sylwester
Veteran Member
Join Date: Oct 2006
Location: Poland
Old 10-23-2010 , 14:15   Re: top10 mysql Problem
Reply With Quote #6

try this:
PHP Code:
public ShowTop10(id) {
    new 
szTemp[512]
    static 
Data[2]
    
    
Data[0] = id

    format
(szTemp,charsmax(szTemp),"SELECT * FROM stats ORDER BY points DESC LIMIT 10")
    
SQL_ThreadQuery(g_SqlTuple,"displaytop10",szTemp,Data,1)
}


public 
displaytop10(FailState,Handle:Query,Error[],Errcode,Data[],DataSize) {
    if(
FailState) {
        
log_amx("SQL Error: %s (%d)"ErrorErrcode)
        return 
PLUGIN_HANDLED
    
}

    if(!
SQL_MoreResults(Query)) {
        return 
PLUGIN_HANDLED
    
}

    new 
id
    id 
Data[0]
    static 
Name[33], PlacePoints
    
    Place 
0

    
new MenuBody[512], lenkeys;
    
len format(MenuBody511"\yStats TOP 10 \r[Version: \y%s\r]^n"VERSION);
    
    do {
        
Place++
        
SQL_ReadResult(Query,7,Name,32)
        
Points SQL_ReadResult(Query,1)

        
len += format(MenuBody[len], 511-len"^n\r%d. %s %d Kills"PlaceNamePoints);

        
SQL_NextRow(Query)
    }while(
SQL_MoreResults(Query))
    
    
keys = ( 1<<1<<1<<);
    
    if( 
get_user_flags(id) & ADMIN_USER 
        
keys |= ( 1<<1<<1<<1<<1<<1<<);

    
show_menu(idkeysMenuBody, -1"StatsMenu");
    
    return 
PLUGIN_HANDLED

Also if you are going to store player name, then you should backquote it (you can use SQL_QuoteString to do it), or someone may damage your database.
__________________
Impossible is Nothing
Sylwester is offline
Stylaa
Senior Member
Join Date: Oct 2009
Location: Flensburg, Germany
Old 10-23-2010 , 14:29   Re: top10 mysql Problem
Reply With Quote #7

okay this works well and can you say me too how i get the Place for a rank command i realy dont know how to ask in mysql for the rownumber after sorting it xD
__________________

Some People brings Happynes by Coming
Some by Going
Stylaa is offline
Send a message via ICQ to Stylaa
Sylwester
Veteran Member
Join Date: Oct 2006
Location: Poland
Old 10-23-2010 , 14:49   Re: top10 mysql Problem
Reply With Quote #8

Use google to find answer.
__________________
Impossible is Nothing
Sylwester is offline
Stylaa
Senior Member
Join Date: Oct 2009
Location: Flensburg, Germany
Old 10-23-2010 , 17:49   Re: top10 mysql Problem
Reply With Quote #9

i dont find anythink whit Google so please help me

i realy have no idea how to find out on which place he is

my only idea is this but i think its a very bad code for this job cuz there will be a lot of entrys in this database i think this can take a lot of time to find the Rank

and its not working too and i dont know why
PHP Code:

register_clcmd
("say place""displayplace");
    
public 
displayplace(id) {
    new 
szTemp[512]
    static 
Data[2]
    
    
Data[0] = id

    format
(szTemp,charsmax(szTemp),"SELECT * FROM stats ORDER BY points")
    
SQL_ThreadQuery(g_SqlTuple,"displayplaceh",szTemp,Data,1)
}


public 
displayplaceh(FailState,Handle:Query,Error[],Errcode,Data[],DataSize) {
    if(
FailState) {
        
log_amx("SQL Error: %s (%d)"ErrorErrcode)
        return 
PLUGIN_HANDLED
    
}

    if(!
SQL_MoreResults(Query)) {
        return 
PLUGIN_HANDLED
    
}

    new 
id
    id 
Data[0]
    static 
Name[33], PlacePoints
    
    
new szSteamId[32]
    
get_user_authid(idszSteamIdcharsmax(szSteamId))
    
    
Place 0

    
do {
        
Place++
        
SQL_ReadResult(Query,7,Name,32)

    if(
szSteamId == Name)
    
ColorChat(0RED"Your Position ist %d!"PREFIXPlace)
    
//Display Rank

        
SQL_NextRow(Query)
    }while(
SQL_MoreResults(Query))

    
    return 
PLUGIN_HANDLED

__________________

Some People brings Happynes by Coming
Some by Going

Last edited by Stylaa; 10-24-2010 at 08:26.
Stylaa is offline
Send a message via ICQ to Stylaa
Reply



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 10:26.


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