Insert multiple values in one field?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
nitediver
Forum Contributor
Posts: 109
Joined: Tue Feb 24, 2009 9:05 am

Insert multiple values in one field?

Post by nitediver »

I want to fix data redundancy in my database.
Is it posible to insert more than one values into one field, and maybe I will need doing some calculation using the values.

This is my database, generating two rows.

Code: Select all

 
---------------------------------
id_order | buyer  | price | product
---------------------------------
000001  | John   | 750   | prod1
---------------------------------
000001  | John   | 750   | prod2
--------------------------------
 
Instead of those, I want to insert multiple values in one field like this.

Code: Select all

 
--------------------------------------
id_order  | buyer  | price | product
--------------------------------------
000001   | 500    | 750   | prod1, prod2
--------------------------------------
 
thanks.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Re: Insert multiple values in one field?

Post by s.dot »

I wouldn't do that.
Keeping separate rows for each item would be the way to go.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
nitediver
Forum Contributor
Posts: 109
Joined: Tue Feb 24, 2009 9:05 am

Re: Insert multiple values in one field?

Post by nitediver »

But, Im using that for shopping cart, thats why I need that.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Re: Insert multiple values in one field?

Post by s.dot »

They are linked by the foreign key id_order
selecting where id_order = '000001' would work
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
Post Reply