0

Hello,

I've looked on google for information about storing multiple pieces of information in one database column, but I can't find anything helpful. If I want to have some sort of etc. inventory, and there is more than one 'item', how would I store multiple items inside the database?

Thanks

4
Contributors
7
Replies
8
Views
7 Years
Discussion Span
Last Post by Designer_101
0

Table Inventory:

user_id | weapon_id | armor_id | etc_items
-------- -+---------------+------------+------------
............ | ................. | .............. | this is the important part

How would you store multiple things or items in that spot for just one user?

1

Table Inventory:

user_id | weapon_id | armor_id | etc_items
-------- -+---------------+------------+------------
............ | ................. | .............. | this is the important part

How would you store multiple things or items in that spot for just one user?

No need to do it that way, you can save all the etc_items for one particular user some other table which refers your primary table's key; even though you can save all the items for single user in just one column with comma seperated values.

0

But what if you don't know how many items there are going to be? Is there a way to set a variable amount of columns?

0

No you can't have a variable number of columns.

The way I would go about it is to create a new table for your etc_items column, and just have it have 2 or more columns as needed,
one being user_id, which should be a foreign key to the user_id field in the user table, and then a item_id field.

That way, if a user has a variable number of items, you can just add/delete records in the new table.

Edited by chaines51: n/a

0

But what if you don't know how many items there are going to be? Is there a way to set a variable amount of columns?

yes, that's the way i mean like above post, when i say a seperate table.You have to insert as many entries for particular record in the master table.
Then while fetching those contents you can do something like -

"select * from secondary_table where weapon id = $w_id"; 
//where $w_id it refers to the primary table.
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.