The SitePoint Forums have moved.

You can now find them here.
This forum is now closed to new posts, but you can browse existing content.
You can find out more information about the move and how to open a new account (if necessary) here.
If you get stuck you can get support by emailing forums@sitepoint.com

If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Store array in mysql

Hi

I have a table with a whole list of sites, and then each user can add those sites to his account, so basically i want to create a field in my users table that stores all the different sites that a person has added to their account.
It's similar to facebook and adding friends...

The best way i can think of to do this is storing the different id's of the sites in an array in one single field - don't know if this is possible or if there's a better way to do this?

Also, then how would I retrieve this list of sites in array form and then how would i add another to this list?

Also, then how would I retrieve this list of sites in array form and then how would i add another to this list?

This is exactly the reason why NOT to store multiple values in a single column in your user table.
It's a many to many relationship (1 user can have many sites, and 1 site can be chosen by many users), so you'll need a third table that connects the site table and the user table (for example called user_sites) with at least two fields:
user_id
site_id

This table will contain a row for each site each user adds to his account.
Thus, adding/deleting sites from an account, and doing queries like "what is the most popular site" are simple.

This is called normalization, and is very important if you want to create good databases. So you might want to study it a bit