How can I optimize this script? -
StRaphael - 26.12.2018
Hello, anyone knows how to optimize this script?
PHP код:
mysql_query(SQL, "SELECT * FROM users");
mysql_store_result();
new totalregistred = mysql_num_rows();
mysql_free_result();
new Cache: cache, variable1, variable2, qstr[90];
for(new i=1;i<totalregistred; i++)
{
mysql_format(SQL, qstr, sizeof(qstr), "SELECT * FROM users WHERE `id` = '%d' AND `variableX` >= 1", i);
tut = mysql_query(SQL,qstr);
if(cache_get_row_count() > 0)
{
variable1 = cache_get_field_content_int(0, "variableY");
variable2 = cache_get_field_content_float(0, "variableZ");
if(variable1 >= x)
{
variable1 = variable2*10;
mysql_format(SQL, var, sizeof(var), "UPDATE `users` SET `variable2`='%d' WHERE `id`='%d'", variable1, i);
mysql_tquery(SQL,var,"","");
}
cache_delete(cache);
}
}
//************Read my last reply************\\
I mean can I make so the function check and affect only registred players who have variableX equal or higher than x? I mean I don't want to check 10000 users at a time, because that would get a lot of time to execute this loop... and function.
I am using BlueG's mysql plugin.
Any help will be highly appreciate!And Marry Christmas everyone!
Re: How can I optimize this script? -
StRaphael - 26.12.2018
Quote:
Originally Posted by ******
Just put the `WHERE` clause in the first query and get rid of the second entirely.
|
Ok, but how can I modify the variable for each one?
I mean, if the first account have variablex = 1 and his id is 8, how can I modify/get another variable from this player with id 8(more likely, how to get the account id from each one who have something equal to something then, to modify the player's column)?
Re: How can I optimize this script? -
StRaphael - 26.12.2018
I updated my test code, so I think now you can understand better what I want to do
Re: How can I optimize this script? -
StRaphael - 26.12.2018
Quote:
Originally Posted by ******
SELECT var2 FROM users WHERE var1 > 1
|
And this is supposed to change for all users(who have var1 > 1) the columns(with different numbers for each player, of course)?
Can you give me a tiny example who do what my script from the top does?
Thank you
Re: How can I optimize this script? -
StRaphael - 26.12.2018
Quote:
Originally Posted by ******
Your code makes no sense. You keep changing variable names and using ones that don't exist.
|
I just gave an example that actually I'm using for a banking system, everyday at a specific hour it calculates the rates for all registered players and I just want to know a way to optimize it..
Re: How can I optimize this script? -
Jefff - 26.12.2018
Its just one line, i think you complicate your life too much
pawn Код:
mysql_tquery(SQL, "UPDATE `users` SET `variable2` = `variable2` * 10 WHERE `variableY` >= x");
Re: How can I optimize this script? -
Logic_ - 27.12.2018
Show us the variables that you're using - what's the sense of hiding names of variables lol