SA-MP Forums Archive
shorten mysql format - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: shorten mysql format (/showthread.php?tid=633909)



shorten mysql format - NealPeteros - 09.05.2017

Is there any way I could shorten this code
PHP код:
mysql_format(mysqlquerysizeof(query), "UPDATE users SET level=%d, money=%d admin=%d lsd=%d cocaine=%d WHERE nick='%s'"scoremoneypnameadminlsdcocaine); 
The format is not complete. I have around 120 datas to be stored in mysql. Is it possible for me to make a shorter version of this?


Re: shorten mysql format - Lbaker - 09.05.2017

I dont got your question but can you show me your query var?


Re: shorten mysql format - NealPeteros - 09.05.2017

Whole code

PHP код:
forward OneMinTimer();
public 
OneMinTimer()
{
    for(new 
iGetPlayerPoolSize(); i++)
    {
        if(
Logged[i] == 1)
        {
            new 
score GetPlayerScore(i); //Gets players score
            
new money GetPlayerMoney(i); //Gets players money
            
new admin PlayerInfo[i][pAdmin];
            new 
lsd PlayerInfo[i][dLSD];
            new 
cocaine PlayerInfo[i][dCocaine];
            new 
query[200], pname[24]; //Creates the variables
            
GetPlayerName(ipname24); //Gets the players name.
            
mysql_format(mysqlquerysizeof(query), "UPDATE users SET level=%d, money=%d admin=%d lsd=%d cocaine=%d WHERE nick='%s'"scoremoneypnameadminlsdcocaine);
            
mysql_query(mysqlquery);
        }
    }
    return 
1;

What I'm trying to say is that mysql_format(mysql, query, sizeof(query), "UPDATE users SET level=%d, money=%d admin=%d lsd=%d cocaine=%d WHERE nick='%s'", score, money, pname, admin, lsd, cocaine); will soon contain 120 datas. It would take a lot of time to list all of them.


Re: shorten mysql format - Banditul18 - 09.05.2017

You can divide that in multiple mysql_format , and use mysql_tquery insteed of mysql_query , i'm surprise that you not say anything by some lag out of that , becasue you says is 120 data so alot of time to send that.

And why you need to save all that in a OneMinuteTimer? I mean WTF
Update the databse only when that values change, of course , for some data it's need that, but not for all that.


Re: shorten mysql format - Lbaker - 09.05.2017

I dont think so. You Can Use \ To Make Your Format Like
PHP код:
mysql_format(mysqlquerysizeof(query), "UPDATE users SET \
 level=%d, \
 money=%d admin=%d lsd=%d cocaine=%d WHERE nick='%s'"
scoremoneypnameadminlsdcocaine); 



Re: shorten mysql format - Vince - 09.05.2017

It's really simple: don't update shit that doesn't need updating. Update stuff immediately, as and when it changes. Yes, you will have more queries overall but they will be short and fast, compared to the huge ones (in a loop, no less) that you're doing now. Also use the primary key (the id) for updating instead of the name. Text searches in SQL are SLOW and the problem will only get worse as the table grows larger.


Re: shorten mysql format - NealPeteros - 09.05.2017

Quote:
Originally Posted by Vince
Посмотреть сообщение
Also use the primary key (the id) for updating instead of the name.
Great idea! How do I do that exactly?


Re: shorten mysql format - Vince - 09.05.2017

Every table should have a primary key. The primary key is a field or a combination of fields that can uniquely identify the row in the table. Theoretically you can make the name the primary key because it's supposed to be unique, but text searches are slow (like I said before). Most people will put the primary key as the first column(s) in the table but it doesn't really matter where it is placed.

Just create an int column, tick auto_increment (may be abbreviated A_I in phpMyAdmin) and then click 'primary key'. It should automatically assign an ID to existing rows. Then in your script create a new specifier in your enum and call it SQLID or something like that. For further updates you use that instead of the name.


Re: shorten mysql format - NealPeteros - 09.05.2017

Quote:
Originally Posted by Vince
Посмотреть сообщение
Every table should have a primary key. The primary key is a field or a combination of fields that can uniquely identify the row in the table. Theoretically you can make the name the primary key because it's supposed to be unique, but text searches are slow (like I said before). Most people will put the primary key as the first column(s) in the table but it doesn't really matter where it is placed.

Just create an int column, tick auto_increment (may be abbreviated A_I in phpMyAdmin) and then click 'primary key'. It should automatically assign an ID to existing rows. Then in your script create a new specifier in your enum and call it SQLID or something like that. For further updates you use that instead of the name.
Paragraph 1 is a check. Don't completely understand paragraph 2. Especially(only) the script part


Re: shorten mysql format - Despacito - 09.05.2017

Quote:

UPDATE users SET cocaine=%d

Don't do drugs guys. It's bad for you and your health/pocket. Pls stahp.