GetPlayerWeaponData and MySql -
v1k1nG - 18.10.2018
Hey, how would you save
PHP Code:
new weapons[13][2];
for (new i = 0; i <= 12; i++)
{
GetPlayerWeaponData(playerid, i, weapons[i][0], weapons[i][1]);
}
In players table without creating a row for every weapon?
Re: GetPlayerWeaponData and MySql -
Calisthenics - 18.10.2018
Not in the `players` table! Make a new table for the weapons and follow this tutorial:
https://sampforum.blast.hk/showthread.php?tid=505081
However add a new column called `slot` and set as UNIQUE KEY the columns (userid, slot) so it will overwrite the previous weapon in the same slot.
Re: GetPlayerWeaponData and MySql -
d3Pedro - 18.10.2018
Quote:
Originally Posted by Calisthenics
Not in the `players` table! Make a new table for the weapons and follow this tutorial: https://sampforum.blast.hk/showthread.php?tid=505081
However add a new column called `slot` and set as UNIQUE KEY the columns (userid, slot) so it will overwrite the previous weapon in the same slot.
|
He better create columns and use loop to save, e.g weapon1, weapon2.
Re: GetPlayerWeaponData and MySql -
Calisthenics - 18.10.2018
Quote:
Originally Posted by ConnorW
He better create columns and use loop to save, e.g weapon1, weapon2.
|
Why 'better'? Say a player is unarmed, is it the same 12 columns with values of 0 than 0 rows? I do not think so.
Re: GetPlayerWeaponData and MySql -
d3Pedro - 18.10.2018
Quote:
Originally Posted by Calisthenics
Why 'better'? Say a player is unarmed, is it the same 12 columns with values of 0 than 0 rows? I do not think so.
|
You simply do a variable for that, and save each weapon. Way much better then a totally new table just for weapons.
Re: GetPlayerWeaponData and MySql -
Kane - 19.10.2018
https://sampforum.blast.hk/showthread.php?tid=505081
Re: GetPlayerWeaponData and MySql -
Calisthenics - 19.10.2018
Quote:
Originally Posted by ConnorW
You simply do a variable for that, and save each weapon. Way much better then a totally new table just for weapons.
|
Using a variable does not prevent you from having 12 "empty" columns. You still define 'better' as what is your preference but not what is right.
If you think a new table "just" for weapons, you could say the same for anything else and end up with your main table having hundreds of columns. A good thumb rule is to keep a table to 10-20 columns max.
https://en.wikipedia.org/wiki/First_..._form#Examples
Violation of 1NF is seen widely on this forum by using columnX or a column separated with multiple values such "0|0|0|1|0|0|0|1".
Another one is storing dates as VARCHAR instead of TIMESTAMP/DATETIME which does not allow you to manipulate the data, get the difference between two dates and what not.
Re: GetPlayerWeaponData and MySql -
d3Pedro - 19.10.2018
Quote:
Originally Posted by Y_Less
This is the exact opposite of good database schema design. If you ever have a column with a numeric suffix you are doing things wrong. A new table just for weapons is absolutely the best way - tables don't have to be (indeed, shouldn't be) monolithic.
|
Code:
new playerweapons[MAX_PLAYERS][12];
SaveWeapons(playerid)
{
new playername[MAX_PLAYER_NAME], string[164];
GetPlayerName(playerid, playername, sizeof(playername));
for (new i = 0; i <= 12; i++)
{
mysql_format(dbconnection, string, sizeof(string), "UPDATE `usertable` SET `weapon%d` = %d WHERE `name` = '%s'", i, playerweapons[playerid][i], playername);
mysql_tquery(dbconnection, string);
}
}
Wouldn't this be the same?
Re: GetPlayerWeaponData and MySql -
jasperschellekens - 19.10.2018
Quote:
Originally Posted by ConnorW
Wouldn't this be the same?
|
Just create a new table.
Re: GetPlayerWeaponData and MySql -
d3Pedro - 19.10.2018
Quote:
Originally Posted by jasperschellekens
Just create a new table.
|
I know you can just create a table for that, but you'll load the table, so instead loading two tables, users and weapons, you can just load one, you get me?
I wasn't me, the one who did requested this help, but i just told him the way i would have saved the player weapons.