Jump to content

Store multiple usernames in the same field as a String?


beennn

Recommended Posts

How can i store multiple usernames in the same field as a string?Each user has a field for freinds and when they click 'add as friend' on someones profile, id like it to add to their friends field so i can use it when it comes to sending message.

Link to comment
Share on other sites

You might store the list of friends as a string of delimited values. A comma, tab, or newline character would work as a delimiter, sort of like:b00bcatMan,e66He4dz,harry123If your server-side platform is PHP, you can separate the list using explode(). This does not allow for convenient joining of tables, however.

Link to comment
Share on other sites

You're not actually supposed to store multiple values in one field - the proper way to do it would be to create a new table that associated two users as friends, e.g.

CREATE TABLE friendship (    requester INT NOT NULL, -- being the ID of the user that requested the friendship    responder INT NOT NULL, -- being the ID of the user that responded to the friendship    PRIMARY KEY (user1, user2));

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...