AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   top10 mysql Problem (https://forums.alliedmods.net/showthread.php?t=141373)

Stylaa 10-23-2010 11:11

top10 mysql Problem
 
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



Sylwester 10-23-2010 11:40

Re: top10 mysql Problem
 
Post stats table definition.

Stylaa 10-23-2010 13:51

Re: top10 mysql Problem
 
1. is Steamid
2. is Kills and in the
8th the PLayrnick
beetween 3 - 7 are ct kills t kills and some other thinks

Sylwester 10-23-2010 13:58

Re: top10 mysql Problem
 
I want to see exact statement ("CREATE TABLE ...") with data types, not description.

Stylaa 10-23-2010 14:02

Re: top10 mysql Problem
 
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)) 


Sylwester 10-23-2010 14:15

Re: top10 mysql Problem
 
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.

Stylaa 10-23-2010 14:29

Re: top10 mysql Problem
 
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

Sylwester 10-23-2010 14:49

Re: top10 mysql Problem
 
Use google to find answer.

Stylaa 10-23-2010 17:49

Re: top10 mysql Problem
 
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




All times are GMT -4. The time now is 10:26.

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