Adding multiple entries to one column in one row?

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
cturner
Forum Contributor
Posts: 153
Joined: Sun Jul 16, 2006 3:03 am
Location: My computer

Adding multiple entries to one column in one row?

Post by cturner »

I am wondering is it possible to add multiple entries to one column in one row? If so, how can this be done? Thanks in advance.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

Usually you would do this with a second table, such as:

Code: Select all

parent_table
id         name
1          car
2          motorcycle

child_table
id    parent_id     name
1     1                  Audi
2     1                  Skoda
3     2                  Kawasaki
4     2                  Ducati
(#10850)
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

A quick and dirty hack is to serialize() an object and store the result
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Kieran Huggins wrote:A quick and dirty hack is to serialize() an object and store the result
Not recommended Image. I'd go with the join.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

Or you could save delimited data in a TEXT field and then explode() it.
(#10850)
Post Reply