Introduce array in database

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
Perfidus
Forum Contributor
Posts: 114
Joined: Sun Nov 02, 2003 9:54 pm

Introduce array in database

Post by Perfidus »

Which is the better way to introduce an array inside a mysql database?
I generate an array with a list of e-mail adresses I have just send and I want to keep this list any time I send a mailing to keep records of who did I sent them. I want to introduce this e-mail list in a database column call emailed.
Which is the best way, if we consideer the posibility I may like to recover the list easily and make it an array again to resend mails again??
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

each row of this table should be an id, email address, date/time type way of tracking when you last sent them something, and possibly the message id you sent them (assuming these are formulaic in nature mass mailings)
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

as already mentionned:

you need a reference to the e-mail you sent (email_id)
you need a reference to the recipient (e-mail or person_id)

sometimes you also want to optional info:

the time when the e-mail was sent (not the same as the creation date of the e-mail)

..
Perfidus
Forum Contributor
Posts: 114
Joined: Sun Nov 02, 2003 9:54 pm

Post by Perfidus »

I didn't explained myself quite well, mates!
I'm sorry.
I have a variable called $unidad which is an array composed by the list of e-mails of the people I have sent an e-mail, I also have a column with name "e-mailed" in which I would like to store this array.
I think the question is:
How to convert the array into a string to be stored in the database and easily converted again in an array again if needed?
The array is a simple one, just e-mails:

1@hotmail.com, 2@hotmail.com, 3@hotmail.com....
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

you don't convert the array into a string. Each email is stored as a seperate row.
Perfidus
Forum Contributor
Posts: 114
Joined: Sun Nov 02, 2003 9:54 pm

Post by Perfidus »

why?
I'm sending the same e-mail to maybe 50 people, why should I create a table just for the emails? Is it not better to store an array with all the recipients???
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

typically, no. What if you want to know the emails you've sent to x,y,z addresses? How easy will it be to construct a query that's simple and works well with it?

If you read this, you may understand why we suggest the things we do. :)
Perfidus
Forum Contributor
Posts: 114
Joined: Sun Nov 02, 2003 9:54 pm

Post by Perfidus »

ok, you are right again!

Thanks!
Post Reply