AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Solved Print stuff from database (https://forums.alliedmods.net/showthread.php?t=308039)

4ever16 06-04-2018 10:58

Print stuff from database
 
I have a database which is called player_player. In that database i have following.

Username | Steam id | Kills | Deaths | Headshots | Points

I have a plugin which prints out my points like this: [SERVERNAME] Your points 1000
I would like it to print out more stuff like kills & deaths but dont have a clue how to.


PHP Code:

public showPlayerRank(id)
{
    static 
query[512];
    
formatex(querycharsmax(query), "SELECT COUNT(*) FROM player_player WHERE points > '%d'"pPoints[id]);
    
log_amx(query)
    static 
data[2];
    
data[0] = id;
    
    
SQL_ThreadQuery(g_hTuple"QueryLoadRank"querydatasizeof(data));
    return 
PLUGIN_HANDLED;
}

public 
QueryLoadRank(failstateHandle:hQueryerror[], errnumdata[], sizeFloat:queuetime)
{
    if( 
failstate == TQUERY_CONNECT_FAILED
    
|| failstate == TQUERY_QUERY_FAILED )
    {
        
set_fail_state(error);
    }
    else
    {
        new 
id data];
        
        if(
SQL_NumResults(hQuery))
        {
            new 
colRank SQL_ReadResult(hQuery0) + 1;
            
client_printcolor(id"/y[/ctr%s/y] Your points /ctr%d"PREFIXcolRank);
        }
    }


Extra stuff in the script.
PHP Code:

    pKills[id] = 0;
    
pDeaths[id] = 0;
    
pHeadshots[id] = 0;
    
pPoints[id] = 0

////////////////////////////////////////////////////////////////////////////////////////////////////////

I have tryed following. But it prints out wrong number, that numbers doesnt exist in database so what am i doing wrong and how to fix it?

PHP Code:

    formatex(querycharsmax(query), "SELECT COUNT(*) FROM player_player WHERE points > '%d'"pKills[id]); 


jimaway 06-04-2018 13:11

Re: Print stuff from database
 
Quote:

Originally Posted by 4ever16 (Post 2595245)
Extra stuff in the script.
PHP Code:

    pKills[id] = 0;
    
pDeaths[id] = 0;
    
pHeadshots[id] = 0;
    
pPoints[id] = 0


why are you messing with the sql query formatting when you have global arrays that store the information you need to print?

also that plugin doesn't print your points from the database, instead it prints the amount of entries in the table that have more points than you

4ever16 06-04-2018 13:31

Re: Print stuff from database
 
Dont really understand what you are saying but...

For example.

If i edit the code to this: There is a table called kills.
PHP Code:

    formatex(querycharsmax(query), "SELECT COUNT(*) FROM mix_players WHERE kills = '%d'"pKills[id]); 

In the console it gets the number correctly. The number is 7 thats my kill count.
But when it prints out it to the server it says 2.

Whats the error?

4ever16 06-04-2018 13:51

Re: Print stuff from database
 
Ok now i understand how it works.

Player 1: 0 kills
Me: 7 kills.
Player 3: 14 kills.

It prints out 2 because it counts the place im in.

So instead of this i would just like to print out my actual kills. Any help?

4ever16 06-04-2018 14:41

Re: Print stuff from database
 
Never mind solved it.


All times are GMT -4. The time now is 04:42.

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