How can I optimize this script?
#1

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 
Cachecachevariable1variable2qstr[90];
for(new 
i=1;i<totalregistredi++)
{
    
mysql_format(SQLqstrsizeof(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'"variable1i);
           
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!
Reply
#2

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)?
Reply
#3

I updated my test code, so I think now you can understand better what I want to do
Reply
#4

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
Reply
#5

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..
Reply
#6

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");
Reply
#7

Show us the variables that you're using - what's the sense of hiding names of variables lol
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)