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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T23:11:33+00:00 2026-05-21T23:11:33+00:00

Sorry for the title, I didn’t know what else to put. I am looking

  • 0

Sorry for the title, I didn’t know what else to put.

I am looking to pull all the information on a user in a single database query.

There are 4 tables:

user  
  - userid (PK)
services
  - serviceid (PK)
languages
  - langid (PK)
areas
  - areaid (PK)
user_services
  - user_services_id (PK)
  - serviceid (FK)
  - userid (FK)
user_languages
  - user_lang_id (PK)  
  - langid (FK)
  - userid (FK)
user_areas
  - user_area_id (PK)
  - areaid (FK)
  - userid (FK)

Both user and user_services I can pull out fine together as they have one row each and are linked by the user.id.

The user_languages and user_areas table are one to many tables and look similar to:

user_lang_id  |  userid  |  langid
      1       |     5    |     2
      2       |     5    |     6
      3       |     5    |    18

user_area_id  |  userid  |  areaid
      1       |     5    |    15
      2       |     5    |     4
      3       |     5    |    13

What I want the array to look like is this:

Array
(
    [id] => 5
    [firstname] => lethal    
    [surname] => Mango
    [gender] => male
    ...
    [langid] => 2
    [langid] => 6
    [langid] => 18
    ...
    [areaid] => London
    [areaid] => Birmingham
    [areaid] => Manchester
}

I have tried a combination SQL JOINs but that didn’t seem to get very far. My last resort was to do 3 seperate queries and join the PHP arrays together at the end (super messy).

Thanks 🙂

  • 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-05-21T23:11:33+00:00Added an answer on May 21, 2026 at 11:11 pm

    We can help you more if you provide us with the structure of the tables, but you can do it with JOINs as long as all your tables share a foreign key to one another. It doesn’t have to be the same key field (such as user_id), but that does make it more straightforward. With joins, you should have something like this:

    select * from user
    left join user_services on user_services.id = user.id
    left join user_languages on user.id = user_languages.id
    left join user_areas on user.id = user_areas.id
    

    This will give you a virtual table that has all of the columns needed. You can then create an array from these columns with the data you need with something like this:

    foreach($query_result as $field => $value) {
        $user[$field] = $value;
    } 
    

    *Note – Code samples are untested and only for sample purposes.

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

Sidebar

Related Questions

Sorry for the crappy title - didn't know how else to say it. I
Sorry for the vague title, I didn't know how else to phrase this. Suppose
I know that title didn't make sense, Im sorry! Its hard to word what
Sorry for the vague title but I really didn't know what title to give
Sorry for the question title, i didn t know how to explain the question
I am sorry I didn't know how to title my question any better, you
first of all: sorry for bad title, didn't knew how to tell my problem
Sorry for a title that bad, but i didn't know how to describe my
I am sorry for the cryptic title but I didn't know how to adequately
It's all in the title really. I've got this SQL query, ugly I know,

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.