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 8094031
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T20:39:46+00:00 2026-06-05T20:39:46+00:00

I have several tables 1 contacts and multiple data. Contacts has an ID field

  • 0

I have several tables 1 contacts and multiple data.

Contacts has an ID field and a Name field; Data has a field called Contacts (as well as other fields).

e.g Contacts

ID - Name
1 - James
2 - Mark
3 - Doug

e.g. data

ID - Contacts - Data
1 - 1,3 - more data
2 - 2 - more data
3 - 2,3,1 - more data

Obviously, the comma-separated numbers link to several people in the contacts table. How can I convert from the comma-separated list to the people’s names? A standard left join won’t work.

Is there a way I can do it in the original query or would I have to add a while inside a foreach inside my original while loop? Such as (the following doesn’t work either but it’s as far as I’ve got):

//original query while {
        $contacts_array = array(implode(",",$db['Contacts'])); 
        foreach ($contacts_array as $contacts_id) 
        { 
            $contacts_query = "SELECT Name FROM data_contacts WHERE ID='$contacts_id'";
            $contacts_result = mysql_query ($contacts_query);
            $contactslist="";
            while($contacts=mysql_fetch_array($contacts_result)){
                $contactslist .= $contacts['Name'].", ";
            } 
        } 
echo $contactslist;
}
  • 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-05T20:39:48+00:00Added an answer on June 5, 2026 at 8:39 pm

    I’ve always stored many-to-many relationships with individual rows instead of comma-separated values:

    ID - Contacts
    1 - 1
    1 - 3
    2 - 2
    3 - 2
    3 - 3
    3 - 1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table called 1 Main Contacts (Main), and several other tables. They
I have a database, with several tables. The main table, called contacts , stores
I have several tables that I am selecting data from. I am trying to
I have a page with several tables on it with the same class name.
I have working website in PHP with a MySQL backend which has several tables
I have several tables with the same structure. How can I select SUM(field) from
I have several tables that contain several strings for fields. Some of these fields
At my work I have several tables with over 200,000 rows of data. I
I have several tables, containing (a.o.) the following fields: tweets: -------------------------- tweet_id ticker created_at
I have two tables: contacts: id, name 1 Alex 2 John documents: id, contactID,

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.