Mysql highscores
#1

PHP код:
forward highscores(playerid);
public 
highscores(playerid)
{
    new 
query[512],results[400],title[64];
    
format(title,sizeof(title),"{00FF00}Highscores");
    
format(query,sizeof(query),"SELECT *  FROM `users` ORDER BY `totalscore` DESC LIMIT 10 ");
    
mysql_query(query);
    
mysql_store_result();
    new 
tRows mysql_num_rows();
    new 
username,totalscore;
    while(
mysql_fetch_row(query))
    {
        
sscanf(query"p<|>d",PInfo[playerid][TotalScore]);
        
format(results,sizeof(results),"%d(%s)\n");
    }
    
ShowPlayerDialog(playerid9863DIALOG_STYLE_LIST,title,results,"Select""Back");
    
mysql_free_result();
    return 
1;

here is my code for viewing highscores of the players on the server.
unfortunately it doesnot work at all

whats wrong in it ?
Reply
#2

First off, you shouldn't select every field when you're selecting a very specific set of data. I also noticed that you did not fetch the account name from the rows you've selected, so you should probably do that too. You'd be far better off writing the query like this

PHP код:
"SELECT name, totalscore FROM `users` ORDER BY totalscore DESC LIMIT 10" 
Obviously replace name in my query with whatever your field for account names is called.

Secondly, you're assigning the data to the incorrect variable. I see you've created variables for the player's username (username should actually be an array), but you're assigning the score you've selected to the player using the high score command. Change your sscanf line to this after making username an array.

PHP код:
sscanf(query"p<|>s[24]d"usernametotalscore); 
Thirdly, you're not formatting your results correctly. You did not include the values you wish to display at the end of your format, and the way you wrote it would also overwrite the previous row you're looping through. Write it like this.

PHP код:
format(results,sizeof(results),"%s%d(%s)\n"resultstotalscoreusername); 
I may be wrong about some of the MySQL stuff there since I've never used the older MySQL plugin versions, but I don't think I am. Hope I helped
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)