SA-MP Forums Archive
Top 10 Mysql. - 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: Top 10 Mysql. (/showthread.php?tid=509196)



Top 10 Mysql. - RaWRZ - 25.04.2014

PHP код:
dcmd_top10(playerid,params[])
{
 
#pragma unused params
 
mysql_query("SELECT Exp, NAME FROM USERS ORDER BY Exp DESC LIMIT 10");
 
mysql_store_result();
 new 
output[512],username[24], scorevariable[5],tmpStr[64];
 while(
mysql_retrieve_row())
 {
 
mysql_fetch_field_row(username"NAME");
 
mysql_fetch_field_row(scorevariable"Exp");
 }
 
mysql_free_result();
 
format(tmpStrsizeof(tmpStr), "%s %d XP\n"usernamestrval(scorevariable));
 
strcat(outputtmpStr);
 
ShowPlayerDialog(playerid8DIALOG_STYLE_MSGBOX"players top10"output"OK""");
 return 
1;

And when i try it out it comes only 1 player with 0 XP?


Re : Top 10 Mysql. - S4t3K - 25.04.2014

https://sampwiki.blast.hk/wiki/for#for

When you use your mysql_fetch_field_row, it tooks only the first statement it finds.
The first solution is to make an unoptimized query per player, the second one is to use a loop.