Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 132073
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T06:12:19+00:00 2026-05-11T06:12:19+00:00

I am in dilemma, do not know which one is better. (I am using

  • 0

I am in dilemma, do not know which one is better. (I am using php and mysql btw)

Lets say I am developing a social community website. A user can add as many friends as he wants. In my database, I have a users table which store user’s details include user’s friends. Should I store the user’s friends in:

Strings => john;bryan;sam;paul;…;

or

Integers => 1;21;50;1779;30;…;

String means store their username. Integer means store their user id.

Which one is better?

If string, it would be a very, very large string(imagine the users have 400 friends, and some usernames are extreme long)

If id, how to list friends on user profile page? Getting list of IDs in one long string (separated by semicolon), use explode function to make it into array. Then using loops to display?? Isn’t troublesome? Is there any other way? If yes, please show some sample code..

OR normally, how would u guys to store the ‘friends’ list in the user table?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T06:12:19+00:00Added an answer on May 11, 2026 at 6:12 am

    Don’t store them as a semi-colon delimited anything. Store them as user IDs in a lookup table. Suppose the user is #2. You might have:

    SourceUserID | FriendUserID 2              1 2              21 2              50 2              1779 2              30 1              // One of John's friends 

    Then to display the list of friends, you query this table restricting it by SourceUserID = 2 and join against the user table to get the names. For example:

    SELECT Name FROM SITE_USERS INNER JOIN USER_FRIENDS ON SITE_USERS.ID = USER_FRIENDS.FriendUserID WHERE SourceUser = ? 

    (Or whatever your parameterised query format is; populate the parameter with the ID of the user whose page you’re displaying.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm building an online store using PHP and MySQL and I ran into a
I am kind of facing a dilemma right now - I know it is
My dilemma is, basically, how to share an enumeration between two applications. The users
I have a little dilemma that maybe you can help me sort out. I've
I have a little dilemma on how to set up my visual studio builds
I've hit a small dilemma! I have a handler called vote; when it is
Where I work we have a little bit of a dilemma... I work on
Okay, my dilemma is this. I have an admin page that I use to
Ok, here is my dilemma I have a database set up with about 5
I'd appreciate people's thoughts on a dilemma I've been struggling with ever since ASP.NET

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.