SQLite TOP players
#1

Ey all! I'm trying to make a players TOP, but it doesn't show the rank, I was trying with differents ways but it still with showing the rank..

I'm using this code:

Код:
	new string[128], query[256], ranks;
	new DBResult:result;
	new DBResult:result2;

	format(query,sizeof(query),"SELECT `NAME` FROM `USERS` ORDER BY (`RANK` * 1) DESC limit 10");
 	result = db_query(Database, query);
	for(new a;a<db_num_rows(result);a++)
	{
		db_get_field(result,0,string,128);
		format(query,sizeof(query),"SELECT `RANK` FROM `USERS` WHERE `NAME` = lower('%s')", string);
		result2 = db_query(Database,query);

		ranks = db_get_field_int(result2, 5);

		new str[40];
		format(str, sizeof(str), "%d. %s - Rank: %d", a+1, string, ranks);
		printf(str);
		//SendFMessage(playerid, white, "%d. %s - Rank: %d", a+1, string, ranks);

		db_next_row(result);
		db_free_result(result2);
	}
	db_free_result(result);
samp-server.exe shows this:



Regards.
PS. Sorry for my bad English, I'm a Spanish guy :v
Reply
#2

All can be done in 1 query and you don't need formatting (the query) too. When selecting 1 field, the fieldid would be 0 and not 5.

PHP код:
new rank_info[200], player_name[MAX_PLAYER_NAME], DBResultresult db_query(Database"SELECT `NAME`,`RANK` FROM `USERS` ORDER BY `RANK` DESC limit 10");
for (new 
adb_next_row(result) != 0a++)
{
    
db_get_field(result0player_namesizeof player_name);
    
format(rank_infosizeof(rank_info), "%d. %s - Rank: %d"1player_namedb_get_field_int(result1));
    
// client message
}
db_free_result(result);
// or dialog.. 
Reply
#3

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
All can be done in 1 query and you don't need formatting (the query) too. When selecting 1 field, the fieldid would be 0 and not 5.

PHP код:
new rank_info[200], player_name[MAX_PLAYER_NAME], DBResultresult db_query(Database"SELECT `NAME`,`RANK` FROM `USERS` ORDER BY `RANK` DESC limit 10");
for (new 
adb_next_row(result) != 0a++)
{
    
db_get_field(result0player_namesizeof player_name);
    
format(rank_infosizeof(rank_info), "%d. %s - Rank: %d"1player_namedb_get_field_int(result1));
    
// client message
}
db_free_result(result);
// or dialog.. 
Oh thanks, now it's working but doesn't show the higher one from the DB:



I should be the first on the list but I don't appear there :V
Reply
#4

Thats because you order it by descending order. Remove DESC
Reply
#5

I see, Gammix's trick seems to skip the first row so change the loop to:
PHP код:
for (new arows db_num_rows(result); rowsa++) 

    
db_get_field(result0player_namesizeof player_name); 

    
format(rank_infosizeof(rank_info), "%d. %s - Rank: %d"1player_namedb_get_field_int(result1)); 
    
// client message 

    
db_next_row(result);

Reply
#6

Quote:
Originally Posted by Sreyas
Посмотреть сообщение
Thats because you order it by descending order.
(??) I'm rank 35 on the DB, (I've created these ranks and these things with some users on my PC) so I should be the number 1 (1. _Ner0x[JMPR] - Rank: 35)

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
I see, Gammix's trick seems to skip the first row so change the loop to:
PHP код:
for (new arows db_num_rows(result); rowsa++) 

    
db_get_field(result0player_namesizeof player_name); 
    
format(rank_infosizeof(rank_info), "%d. %s - Rank: %d"1player_namedb_get_field_int(result1)); 
    
// client message 
    
db_next_row(result);

Now it's not working lol:

Reply
#7

Err, are you sure you placed db_next_row inside the loop? It should have worked, at least I don't see any mistake myself.
Reply
#8

Quote:
Originally Posted by Ner0x96
Посмотреть сообщение
(??) I'm rank 35 on the DB, (I've created these ranks and these thinks with some users on my PC) so I should be the number 1 (1. _Ner0x[JMPR] - Rank: 35)



Now it's not working lol:

i misinterpreted your question i thought ranks should be get by ascending order as thats normal case no? -_-

try this
PHP код:
 rows db_num_rows(result);
for (new 
arowsa++,db_next_row(result))  

 
db_get_field(result0player_namesizeof player_name); 
 
format(rank_infosizeof(rank_info), "%d. %s - Rank: %d"1player_namedb_get_field_int(result1)); 
    
// client message   

Reply
#9

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
Err, are you sure you placed db_next_row inside the loop? It should have worked, at least I don't see any mistake myself.
Lol I forgot it, my wrong sorry.
It's working now, thanks all for helping me <3
Reply
#10

Nvm, fixed, I forgot to use strcat XD
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)