Convert MySQL r7 to MySQL r38 -
ReD_HunTeR - 28.01.2015
fixxed.
Re: Convert MySQL r7 to MySQL r38 -
ReD_HunTeR - 29.01.2015
bump*
Re: Convert MySQL r7 to MySQL r38 -
RedFusion - 29.01.2015
pawn Код:
new connectionHandle;
// Threaded Query
mysql_tquery(connectionHandle, "SELECT score, username FROM usertable ORDER BY score DESC LIMIT 10", "OnTopPlayersLoaded");
// Called when the data is loaded to cache
forward OnTopPlayersLoaded();
public OnTopPlayersLoaded()
{
for(new row, rows = cache_get_row_count(connectionHandle); row < rows; row ++)
{
new
username[MAX_PLAYER_NAME + 1],
score
;
cache_get_field_content(row, "username", username, connectionHandle);
score = cache_get_field_content_int(row, "score", connectionHandle);
printf("[Row %i] Username: %s, Score: %i", row, username, score);
}
return 1; // prevent memory leak
}
Re: Convert MySQL r7 to MySQL r38 -
PowerPC603 - 29.01.2015
You forgot to "return 1;" inside that callback.
If it isn't there, the plugin won't know when the callback has finished executing (or when you're done reading the results) and the cache won't be cleared, resulting in memory-leaks.
Re: Convert MySQL r7 to MySQL r38 -
RedFusion - 29.01.2015
Oh shit i never knew, thanks for the tip!
Re: Convert MySQL r7 to MySQL r38 -
ReD_HunTeR - 29.01.2015
pawn Код:
forward OnTopScores(playerid);
public OnTopScores(playerid)
{
for(new row, rows = cache_get_row_count(mysql); row < rows; row ++)
{
new username[MAX_PLAYER_NAME + 1], score, string[128];
cache_get_field_content(row, "Username", username, mysql);
score = cache_get_field_content_int(row, "Scores", mysql);
format(string, sizeof(string), "%i. Username: %s, Scores: %i", row, username, score);
ShowPlayerDialog(playerid,DIALOG_TOPSTATS,DIALOG_STYLE_MSGBOX,"Top Scored",string,"Okey","");
return 1;
}
return 1;
}
can u fix this? i want this dialog to display top 10 scored people...
Re: Convert MySQL r7 to MySQL r38 -
RedFusion - 29.01.2015
Something like this:
pawn Код:
forward OnTopScores(playerid);
public OnTopScores(playerid)
{
new full_info[500];
for(new row, rows = cache_get_row_count(mysql); row < rows; row ++)
{
new
username[MAX_PLAYER_NAME + 1],
score,
sub_info[50]
;
cache_get_field_content(row, "Username", username, mysql);
score = cache_get_field_content_int(row, "Scores", mysql);
format(sub_info, sizeof sub_info, "%02i. Username: %s, Score: %i\n", row + 1, username, score);
strcat(full_info, sub_info);
}
ShowPlayerDialog(playerid, DIALOG_TOPSTATS, DIALOG_STYLE_MSGBOX, "Top Scores", full_info, "Close", "");
return 1;
}