MySQL Leaderboard - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: MySQL Leaderboard (
/showthread.php?tid=600891)
MySQL Leaderboard -
Agiss100 - 14.02.2016
Hello,
i got the following code.
I want to get the top 5 players ordered by score, and use them in a format. How to assign the stuff from the database to the variables "name" and "score"?
Код:
CMD:top(playerid, params[])
{
new query[500];
new name[5][24];
new score[5][10];
new num;
mysql_format(mysql, query, sizeof(query), "SELECT name, score FROM accounts ORDER BY score DESC LIMIT 5");
mysql_tquery(mysql, query, "");
cache_get_field_content(0, "name", name);
score = cache_get_field_content_int(0, "score", mysql);
return 1;
}
Re: MySQL Leaderboard -
zPain - 14.02.2016
You must fetch the query result in a callback.
PHP код:
// command
mysql_tquery(mysql, query, "leaderboard", "i", playerid);
// callback
forward leaderboard(playerid);
public leaderboard(playerid) {
// code
}
Re: MySQL Leaderboard -
Agiss100 - 14.02.2016
Thanks, but still, how to assign these to the variables?
Re: MySQL Leaderboard -
zPain - 14.02.2016
This should do it just fine.
PHP код:
public leaderboard(playerid) {
new rows = cache_num_rows(mysql);
new message[145];
new name[25], score;
for(new r = 0; r < rows; ++r) {
cache_get_field_content(r, "name", name, mysql, sizeof name);
score = cache_get_field_content_int(r, "score", mysql);
format(message, sizeof message, "%d. %s - Score: %d", (r + 1), name, score);
SendClientMessage(playerid, -1, message);
}
return 1;
}