Mysql to sql.
#1

Is there any way to pass this code to sql?
Yes, my question is something stupid, but i do not know anything about mysql.

Код:
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;
}
Reply
#2

Yes, the SQL Query will work.
Btw, your code can be optimised to:
PHP код:
stock LoadTop10()
{
    
mysql_function_query(mysql"SELECT * FROM `players` ORDER BY `score` DESC LIMIT 10 "false"LoadScores"""""); //init the load scores function with no cache
    
return 1// returning the function true
}
public 
LoadScores()
{
    new 
rowsfields;
    
cache_get_data(rowsfieldsmysql); //returning all 10 players & all their rows/fields
    
if(!rows)//if there are rows to be retrived continue
    
{
               
printf("There are no players saved with score..");
               return 
1;
        }
    new 
dest[24], score;
        
printf("top 10:");
    for(new 
0rowsi++) //loop through all the found rows and pull the following
    
{
        
cache_get_row(i"pName"dest);         //get the name of the player on the position i
        
score cache_get_row_int(i"score");  //get the score of the player on the position i
        
printf("#%d %s with %d"destscore); //print the player on the position i name and score
    
}
    return 
1;

Reply
#3

MySQL to SQL ...
Your code contains already some SQL language.
Reply
#4

First, IDK why but i am having this feeling that you dont know that MySQL and SQL are the same thing.

Second, Your provided code would absolutely work. If you dont know how to connect to a database and all, You can search the forum for MySQL tutorial.

P.S: I see you're using R33+ MySQL, you might wanna update it to R40+. (latest R41-4)
Reply
#5

I think that he has been to roleplay servers and want to build something on his own, but he really doesn't understand what he is doing.
Reply
#6

Quote:
Originally Posted by 10MIN
Посмотреть сообщение
Yes, the SQL Query will work.
Btw, your code can be optimised to:
PHP код:
stock LoadTop10()
{
    
mysql_function_query(mysql"SELECT * FROM `players` ORDER BY `score` DESC LIMIT 10 "false"LoadScores"""""); //init the load scores function with no cache
    
return 1// returning the function true
}
public 
LoadScores()
{
    new 
rowsfields;
    
cache_get_data(rowsfieldsmysql); //returning all 10 players & all their rows/fields
    
if(!rows)//if there are rows to be retrived continue
    
{
               
printf("There are no players saved with score..");
               return 
1;
        }
    new 
dest[24], score;
        
printf("top 10:");
    for(new 
0rowsi++) //loop through all the found rows and pull the following
    
{
        
cache_get_row(i"pName"dest);         //get the name of the player on the position i
        
score cache_get_row_int(i"score");  //get the score of the player on the position i
        
printf("#%d %s with %d"destscore); //print the player on the position i name and score
    
}
    return 
1;

Dude, do you think this works
Код:
mysql_function_query(mysql, "SELECT * FROM `players` ORDER BY `score` DESC LIMIT 10 ", false, "LoadScores", "", "");
in sql?
Reply
#7

Look, MySQL means, My-Structured Query Language. and SQL is Structured Query Language. MySQL is a SQL Client. Also, MySQL_function_query i believe its MySQL R7 plugin. This is not recommended to use, instead use MySQL R41-4 the latest one. It has threaded support too.
Reply
#8

Quote:
Originally Posted by GTLS
Посмотреть сообщение
Look, MySQL means, My-Structured Query Language. and SQL is Structured Query Language. MySQL is a SQL Client. Also, MySQL_function_query i believe its MySQL R7 plugin. This is not recommended to use, instead use MySQL R41-4 the latest one. It has threaded support too.
Thanks dude, but the problem is that i do not know all the functions of MYSQL and i know they are twice as SQL and sometimes people say that it becomes more optimal.
Reply


Forum Jump:


Users browsing this thread: 4 Guest(s)