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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T21:21:52+00:00 2026-05-15T21:21:52+00:00

I’m trying to join multiple myqsl tables and then process resulting arrays using PHP

  • 0

I’m trying to join multiple myqsl tables and then process resulting arrays using PHP but I’m having problems manipulating my data to get the groupings I’d like.

table.users
+—————
uid
name

table.profile_values
+———————–
fid
uid
category_value

table.profile_fields
+———————
fid
category_title

Here is my sql query:

SELECT users.name, profile_fields.category_title, profile_values.category_value FROM profile_values 
    INNER JOIN profile_fields
        ON profile_values.fid=profile_fields.fid
    INNER JOIN users
        ON users.uid=profile_values.uid
    ORDER BY users.name ASC

Using I while loop over fetch_array(), as expected, I get an array for each row number which looks something like:

Array (
    [0] => Array (
            [name] => Bob
            [category_title] => Occupation 
            [category_value] => IT
            ) 
    [1] => Array ( 
            [name] => Bob 
            [category_title] => Previous Experience 
            [category_value] => Very little.
            ) 
    ...
)

The output I’m actually looking to generate is:

Array( 
    [name] => array(
            [category_title 1] => value 1
            [category_title 2] => value 2
            ...
    )
    ....
)

I’ve spent the vast part of a day looking at various examples and haven’t been able to find one that helps me understand the best place to interject and group my data. I’ve seen examples using GROUP_CONCAT, which is similar to what I want, but I’d like to keep my data in arrays if possible.

Should I be using a nested foreach loops after I have my rows assigned to arrays, using a GROUP BY in my sql statement, or a combination of both?

  • 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-15T21:21:52+00:00Added an answer on May 15, 2026 at 9:21 pm

    Use php to create the array you want then. Maybe something like:

    $result = mysql_query($sql) or die(mysql_error());
    $newArray = array();
    while($row = mysql_fetch_assoc($result)){
        $newArray[$row['name']][$row['category_title']][] = $row['category_value'];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 471k
  • Answers 471k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The array will be an object on the heap containing… May 16, 2026 at 3:15 am
  • Editorial Team
    Editorial Team added an answer hour <12 ? "Godd morning" : "Good afternoon" This ternary… May 16, 2026 at 3:15 am
  • Editorial Team
    Editorial Team added an answer You need to initialize each level, but you can do… May 16, 2026 at 3:15 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.