28.06.2016, 13:52
pawn Код:
stock LoadTop10()
{
new Query[128];
mysql_format(mysql, Query, sizeof(Query), "SELECT * FROM `players` ORDER BY `score` DESC LIMIT 10 "); //not tested, might need to fix the query
mysql_function_query(mysql, Query, false, "LoadScores", "", ""); //init the load scores function with no cache
return 1; // returning the function true
}
public LoadScores()
{
new rows, fields;
cache_get_data(rows, fields, mysql); //returning all 10 players & all their rows/fields
if(rows)//if there are rows to be retrived continue
{
for(new i = 0; i < rows; i++) //loop through all the found rows and pull the following
{
new dest[24], score;
cache_get_row(i, "pName", dest); //get all the player names pulled from the query
score = cache_get_row_int(i, "score"); //pull all the scores from the rows retrived
printf("top 10 players are %s wtih scores of %d", dest, scores); //print the result when ever LoadScores is called.
}
else
{
printf("There are no players saved with score.."); //if there were no rows found in the query called in LoadTop10
//escape ect..
}
return 1;
}
(also idk why the formatting fucked up but w/e.