shorten mysql format -
NealPeteros - 09.05.2017
Is there any way I could shorten this code
PHP код:
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);
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 i; i < GetPlayerPoolSize(); 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(i, pname, 24); //Gets the players name.
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);
mysql_query(mysql, query);
}
}
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(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);
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.