Posts: 34
Threads: 0
Joined: Jul 2018
First of all you need to have column for cash in Players table. In this example, I will use cash as an column of value of cash.
So, here it is, but notice that: I don't use easy sqlite and am in a hurry, so take this code and do the same with easy sqlite.
PHP код:
CMD:toprich(playerid, params[])
{
new toprich, DBResult:result;
result = db_query(<DB>, "SELECT max(cash) FROM Players");
if(db_num_rows(result))
toprich = db_get_field_int(result);
db_free_result(result);
va_SendClientMessage(playerid, -1, "Max amount of cash is %d", toprich); //FROM YSI
return 1;
}
Also notice:
<DB> is the placeholder of real database (you create it first like this:
new DB:dbname;)
Posts: 1,228
Threads: 1
Joined: May 2018
Reputation:
0
The include does not provide ORDER BY clause and there is lack of documentation too. It is more complex than using default sa-mp natives and get the job done.
MAX returns the highest value on cash, you need to select the columns you want (name, cash) and order it by highest (DESC).
If you search "samp sqlite top 10", you can find many threads.
Posts: 357
Threads: 6
Joined: Feb 2018
Код:
new str[200], name[MAX_PLAYER_NAME], DBResult: result = db_query(db_open("Top.db"), "SELECT `Name`,`Kills` FROM `Players` ORDER BY `Kills` DESC limit 10");
for (new a, rows = db_num_rows(result); a < rows; a++)
{
db_get_field(result, 0, name, sizeof(name));
format(str, sizeof(str), "%d. %s - Kills: %d\n", a + 1, name, db_get_field_int(result, 1));
ShowPlayerDialog(playerid, 0, DIALOG_STYLE_MSGBOX, "Top Rich List", str , "Exit", "");
db_next_row(result);
}
Posts: 357
Threads: 6
Joined: Feb 2018
oh my mistake
Код:
new str[200], name[MAX_PLAYER_NAME], DBResult: result = db_query(db_open("Top.db"), "SELECT `Name`,`Kills` FROM `Players` ORDER BY `Kills` DESC limit 0,10");
for (new a, rows = db_num_rows(result); a < rows; a++)
{
db_get_field(result, 0, name, sizeof(name));
format(str, sizeof(str), "%d. %s - Kills: %d\n", a + 1, name, db_get_field_int(result, 1));
db_next_row(result);
}
ShowPlayerDialog(playerid, 0, DIALOG_STYLE_MSGBOX, "Top Rich List", str , "Exit", "");
try this!
Posts: 296
Threads: 32
Joined: Jun 2018
Reputation:
0
plz can you provide me an example code I dont know much about sqlite
Posts: 296
Threads: 32
Joined: Jun 2018
Reputation:
0
FIXED now working thanks you calisthenics + REP