/top10 with mysql. -
budelis - 09.09.2011
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..
Re: /top10 with mysql. -
[HiC]TheKiller - 09.09.2011
Lets just say that we are doing the top 10 players by score. Your variables are probably not going to be like the following but it's a example
pawn Code:
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();
-
budelis - 10.09.2011
But i think it's get only my position.
How i can do with dialog like that:
pawn Code:
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
Re: /top10 with mysql. -
Vince - 10.09.2011
pawn Code:
// 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", "");
Re: /top10 with mysql. -
budelis - 10.09.2011
Thank you both.But i want to ask one more thing.How to make "your postion is %d of %d? i have mean i have do with my postion,but i don't know how to do of what position your are if max registered players is 10 then will be
Your position is 2 of 10
Re: /top10 with mysql. -
[HiC]TheKiller - 10.09.2011
You could either use the count function in SQL or do the following
pawn Code:
stock ReturnUserCount()
{
mysql_query("SELECT username FROM `usertable`");
mysql_store_result();
new users = mysql_num_rows();
mysql_free_result();
return users;
}
I wouldn't really recommend calling that often if you had a big database.
Re: /top10 with mysql. -
Gh0sT_ - 10.09.2011
HiC >>> why not just mysql_row_count?
-
budelis - 10.09.2011
I try to do but i don't know you to do and with your position? i try to do:
pawn Code:
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;
}
But,i don't get players for ex:
pawn Code:
Player1 = 2000XP
Player2 = 1000XP
I'am "Player1" and when i write /top10 i only get my
but i want to do that:
pawn Code:
1.Player1 2000XP
2.Player2 1000XP
pawn Code:
mysql_query("SELECT Exp, Name FROM playerdata ORDER BY Exp DESC LIMIT 10");
Then how "DESC LIMIT 10" and limit will be not 10,but that how much is registered players.