tags:

views:

55

answers:

1

I was wondering if i had a mysql field named names that had many names in the same field that a user can pull from it how should my field be setup?

For example if the user entered about 20 names into the same name field how should my mysql table be setup if my table is not set up correctly.

And how can I display each 20 names from the name field using php?

I currently have it setup

TABLE 'array_entries' (
  'user_id' int(11) NOT NULL auto_increment,
  'name' text
);
+1  A: 

You have two solutions here: one is to use just one name field and splits the field using the following code:

$names = explode (" ", $stored_names );

The best approach, though is to insert each name on a different row, duplicating the user id:

| id | user_id | name              |
|  1 |       1 | John              |
|  2 |       1 | Peter             |
|  3 |       2 | Mary              |
|  4 |       1 | JP                |
|  5 |       2 | Maryann           |

In order to fetch every name for a single user, search your table according to the supplied user id and fetch all relevant rows.

Anax