MYSQL table
#1

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

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

Create a table called 'guns' and run this query...

PHP код:
ALTER TABLE guns ADD charid INT(12); 
ALTER TABLE guns ADD gunid INT(12AFTER charid;
ALTER TABLE guns ADD ammo INT(12AFTER gunid;
ALTER TABLE guns ADD slot INT(12AFTER ammo
Quote:
Originally Posted by webby
Посмотреть сообщение
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
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.
Reply
#4

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(12AFTER charid;
ALTER TABLE guns ADD ammo INT(12AFTER gunid;
ALTER TABLE guns ADD slot INT(12AFTER 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 , appreciate your help +REP
Reply
#5

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

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

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

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

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 (accountidweaponid),
    
CONSTRAINT FOREIGN KEY (accountidREFERENCES Account(idON DELETE CASCADE ON UPDATE CASCADE,
    
CONSTRAINT FOREIGN KEY (weaponidREFERENCES Weapon(idON DELETE RESTRICT ON UPDATE RESTRICT
); 
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)