Quote:
Originally Posted by Tass007
I think you misunderstood me. I know how to save to databases and I know MySQL functions, I'm just new to the idea of having multiple tables for the same sort of thing. I think I reworded my question wrong; I was just wanting advice on how to insert the car mod into the child board of vehicle_mods and how to load from it. Plus if this isn't the place to ask questions where do I go? Go post a topic on the scripting help board? Well...Aren't you meant to look around for a similar situation you're in or topic that you're looking for and read it and if you have any questions ask? Because if I'm not allowed to post here then I'll go make another topic on the exact same thing in the Scripting Help board.
|
I referred to the misknowledge in how to add columns.
So for the answer for your question, I don't really understand deeply the code you've sent, but I can extend the explanation on the first post.
Which is basically kind of building a NoSQL, but in SQL
Say you're given an entire row, you have many columns.
You have player data, name, password etc, and then you have a set of columns for the private vehicle, private house and many other things.
Everything in one row.
Now, a few months pass, and you feel like having to increase the number of private things.
Like, 2 private houses, 2 private vehicles, two private weapons on spawn.
So what would you typically do if you already have everything in one table? You'd more columns
But hey, there are already HouseID and HousePosX Y and Z, how do I scale that?
Most people would just add a number to it, to indicate a multi set of things.
So now you're basically building a really long table horizontally. ( <- (horizontal) -> )
So now we approach the first issue, and that's a mess of data, you open your table and see lots of data and it only grows bigger downside and rightside, because you're building horizontally as well with columns.
And here comes the the foreign keys in:
Lets erase all the things we had until now except the user data.
You by now, probably have the player id, name, password and a bit of other tasty data you've collected.
Now, lets imagine we're creating a separate table called `
houses`, `
vehicles`.
Houses will hold a preset of house data that we created all over GTA and vehicles will need to be created dynamically - as people buy more and more vehicles.
Now, you'd probably create the normal columns for them, and add to the end of each table an id, such as `
OwnerId` which will hold the account id of the owner.
And here comes the important stuff, make the ownerid be a foreign key which refrences to the player's account id.
Which means
PHP Code:
CREATE TABLE Vehicles (
ID int NOT NULL,
VehicleID int NOT NULL,
VehiclePlate int NOT NULL,
AccountID int,
PRIMARY KEY (ID),
FOREIGN KEY (AccountID) REFERENCES accounts(ID)
);
Which basically means:
Create a table with this data:
ID,
VehicleID,
VehiclePlate
AccountID,
Now make a conection between AccountID column here with `table` accounts ( column `ID` )
And now, the PRIMARY KEY is the referenced key.
in `accounts` table, the ID should be a primary key.
Primary key basically is the key which represents these rows, and you can link from any other table to this
In our case, the account ID is the one we link to.
Now, as for the houses, we do the same, but for OwnerID
PHP Code:
CREATE TABLE Houses (
ID int NOT NULL,
HouseLabel int NOT NULL,
HouseCost int NOT NULL,
OwnerID int,
PRIMARY KEY (ID),
FOREIGN KEY (OwnerID) REFERENCES accounts(ID)
);
Now, what are the advantages of this after all
First of all its not messy.
Second, its
scalable, which means you can link as many rows you wish to one player.
So you can now give a player buy 2 houses or 1337 houses, as long as you link the account right with the foreign keys and primary.
(Remember that you have to create a primary key for the "reference to this")
But be aware of the other things I haven't mentioned, but is written in the first post under `
Creating relations`
I hope I explained it well enough and correctly