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

  • SEARCH
  • Home
  • 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 9161239
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T13:55:27+00:00 2026-06-17T13:55:27+00:00

In my table ‘users’ there are ‘friends’ , Like this : +—-+——+———+ | id

  • 0

In my table ‘users’ there are ‘friends’ ,

Like this :

+----+------+---------+
| id | name | friends |
+----+------+---------+
|  1 | a    | 0,1,2   |
|  2 | b    | 0,1,3   |
|  3 | c    | 0,1     |
+----+------+---------+

How do I use the explode function to get the friends id one by one (not 0,1,2) that are separated by a comma (,) ;

How do I select the id? (Example) :

$sql = Select id from users where id = (exploded)

if (mysql_num_rows($sql) > 0 ) {
  $TPL->addbutton('Unfriend');
}else{
  $TPL->addbutton('Add as Friend')
}
  • 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. Editorial Team
    Editorial Team
    2026-06-17T13:55:28+00:00Added an answer on June 17, 2026 at 1:55 pm

    The solution here is actually a slight change in your database structure. I recommend you create a “many-to-many” relational table containing all of the users friends referenced by user.

    +---------+-----------+
    | user_id | firend_id |
    +---------+-----------+
    |       1 |         2 |
    |       1 |         3 |
    |       1 |         4 |
    |       2 |         1 |
    |       2 |         5 |
    +---------+-----------+
    

    If you are storing lists of values within one field then that is the first sign that your database design is not quite optimal. If you need to search for a numerical value, it’ll always be better to place an index on that field to increase efficiency and make the database work for you and not the other way around 🙂

    Then to find out if a user is a friend of someone, you’ll query this table –

    SELECT * FROM users_friends WHERE 
      `user_id` = CURRENT_USER AND `friend_id` = OTHER_USER
    

    To get all the friends of a certain user you would do this –

    SELECT * FROM users_friends WHERE `user_id` = CURRENT_USER
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

table: USERS | id | name | city_id | | 1 | jonh |
Table one: products Which have fields like products_id products_price master_categories_id Table two: specials .
Table schema is set up something like this: userID Points timestamp 1 40 3
Table structure: users: uid, name friendships: uid1, uid2 game_membership: gid, uid basically I'm trying
table : id (integer primary key) data (blob) I use mysql and sqlalchemy. To
Table A has two columns: ID and name I want to input 3 ID
Table #1: qa_returns_items Table #2: qa_returns_residues I have a long time trying to get
TABLE 1 is like following A B 1 x 2 y 3 z 4
table order id_order | date | id_product | id_size | id_gender | name |
Table DEPARTMEnT TABLE EMPLOYEE There is the Operations Department which has not any employee.

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.