MYSQL table - 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: MYSQL table (
/showthread.php?tid=640363)
MYSQL table -
Puff - 01.09.2017
Hi, how would you create a table for this line..
Код:
format(line, sizeof(line), "INSERT INTO `guns` ( `charid`, `gunid`, `ammo`, slot) VALUES (%d, %d, %d, %d) ",GetPVarInt(playerid, "CharID"),storedWeaponID[playerid][slot],storedWeaponAmmo[playerid][slot],slot);
Код:
format(line, sizeof(line), "SELECT `gunid`, `ammo`, `slot` FROM `guns` WHERE `charid` = %d ",GetPVarInt(playerid, "CharID"));
Thanks.
Re: MYSQL table -
webby - 01.09.2017
You enter in PHPMyAdmin, select the database, at the bottom you will have a category „create table” -
https://gyazo.com/727c94aba5e7d9271529db52807533ab, enter the table name „guns” and 4 columns.
And then -
https://gyazo.com/b936f4557d52a863bb7391a445274955
Re: MYSQL table -
Luke_James - 01.09.2017
Create a table called 'guns' and run this query...
PHP код:
ALTER TABLE guns ADD charid INT(12);
ALTER TABLE guns ADD gunid INT(12) AFTER charid;
ALTER TABLE guns ADD ammo INT(12) AFTER gunid;
ALTER TABLE guns ADD slot INT(12) AFTER ammo;
Quote:
Originally Posted by webby
|
The integer values should be longer than five. Also, it's much more useful to show him how to write and execute queries than showing him how to create columns and tables via the user interface.
Re: MYSQL table -
Puff - 01.09.2017
Quote:
Originally Posted by Luke_James
Create a table called 'guns' and run this query...
PHP код:
ALTER TABLE guns ADD charid INT(12);
ALTER TABLE guns ADD gunid INT(12) AFTER charid;
ALTER TABLE guns ADD ammo INT(12) AFTER gunid;
ALTER TABLE guns ADD slot INT(12) AFTER ammo;
The integer values should be longer than five. Also, it's much more useful to show him how to write and execute queries than showing him how to create columns and tables via the user interface.
|
That's right, thanks man
![Smiley](images/smilies/smile.png)
, appreciate your help +REP
Re: MYSQL table -
Vince - 01.09.2017
Quote:
Originally Posted by Luke_James
Also, it's much more useful to show him how to write and execute queries than showing him how to create columns and tables via the user interface.
|
Which is why you use ALTER TABLE instead of CREATE TABLE? O_o
Re: MYSQL table -
Puff - 01.09.2017
Quote:
Originally Posted by Vince
Which is why you use ALTER TABLE instead of CREATE TABLE? O_o
|
Yup noticed that too.. I did change it to CREATETABLE though
Re: MYSQL table -
Banditul18 - 01.09.2017
Quote:
Originally Posted by Luke_James
The integer values should be longer than five.
|
That value that you put in lenght its a little bit irelevant, its used only for display. Integer will always have same values beside you put 12 or 5 in lenght thingy
https://dev.mysql.com/doc/refman/5.7...ger-types.html
That why for gun id and slot i personaly prefer to use small integer unsigned becasue they have exact size that you need. Its just an opinion...
Re: MYSQL table -
Luke_James - 01.09.2017
Quote:
Originally Posted by Vince
Which is why you use ALTER TABLE instead of CREATE TABLE? O_o
|
Yes, with the assumption that the OP would be able to figure out how to create a table himself via a query. Which is not a difficult thing to deduce from the instructions I had provided him re creating columns.
Re: MYSQL table -
Vince - 01.09.2017
That wasn't really my point. My question to you is: why create an empty table to fill it later instead of creating the entire table in one go? These days I much rather prefer to type everything by hand because I find it at least equally as fast as clicking through a GUI.
This is what a typical CREATE TABLE statement looks like:
PHP код:
CREATE TABLE AccountWeapon (
accountid INT UNSIGNED NOT NULL,
weaponid INT UNSIGNED NOT NULL,
ammo INT UNSIGNED NOT NULL,
CONSTRAINT PRIMARY KEY (accountid, weaponid),
CONSTRAINT FOREIGN KEY (accountid) REFERENCES Account(id) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT FOREIGN KEY (weaponid) REFERENCES Weapon(id) ON DELETE RESTRICT ON UPDATE RESTRICT
);