09.09.2011, 11:16
Hi all.Maybe anybody can show me how to do top10 of players with mysql?and with my postion for ex:
You are a position 1..
You are a position 1..
mysql_query("SELECT score, username FROM usertable ORDER BY score DESC LIMIT 10");
mysql_store_result();
new id;
while(mysql_retrieve_row())
{
id ++;
new username[24], scorevariable[5];
mysql_fetch_field_row(username, "username");
mysql_fetch_field_row(scorevariable, "score");
printf("Position %d: Username - %s | Score: %d", id, username, strval(scorevariable));
}
mysql_free_result();
1.Player1 - %d XP
2.Player2 - %d XP
3.Player3 - %d XP
4.Player4 - %d XP
5.Player5 - %d XP
6.Player6 - %d XP
7.Player7 - %d XP
8.Player8 - %d XP
9.Player9 - %d XP
10.Player10 - %d XP
Your position in top is %d.With score %d
// Declare this before starting the loop
new
output[512], // Make this larger if you need to
tmpStr[64];
// This should be in the loop, after you fetched the row from the db
format(tmpstr, sizeof(tmpstr), "%d. %s - %d XP\n", id, username, score);
strcat(output, tmpStr);
// And then after mysql_free_result
ShowPlayerDialog(playerid, 1234, DIALOG_STYLE_LIST, "Table Name", output, "Ok", "");
stock ReturnUserCount()
{
mysql_query("SELECT username FROM `usertable`");
mysql_store_result();
new users = mysql_num_rows();
mysql_free_result();
return users;
}
mysql_query("SELECT Exp, Name FROM playerdata ORDER BY Exp DESC LIMIT 10");
mysql_store_result();
new id,output[512],username[24], scorevariable[5],tmpStr[64],tmpStr2[64];
while(mysql_retrieve_row())
{
id ++;
mysql_fetch_field_row(username, "Name");
mysql_fetch_field_row(scorevariable, "Exp");
format(tmpStr, sizeof(tmpStr), "%d. %s %d XP\n", id, username, strval(scorevariable));
strcat(output, tmpStr);
}
format(tmpStr2, sizeof(tmpStr2), "Your position is %d of %d with %d XP",id,ReturnUserCount(),strval(scorevariable));
strcat(output, tmpStr2);
mysql_free_result();
ShowPlayerDialog(playerid, 8, DIALOG_STYLE_MSGBOX, "players top10", output, "OK", "");
return 1;
}
Player1 = 2000XP
Player2 = 1000XP
1.Player1 2000XP
1.Player1 2000XP
2.Player2 1000XP
mysql_query("SELECT Exp, Name FROM playerdata ORDER BY Exp DESC LIMIT 10");