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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T00:28:42+00:00 2026-06-04T00:28:42+00:00

This seems easy but haven’t found the magic search term yet. One table ID

  • 0

This seems easy but haven’t found the magic search term yet.

One table

ID | UserID | Mod_number

1      43      1
2      43      2
3      43      3 
4      43      4
5      55      1
6      55      2

I want to return a query that looks like:

UserID | Mod_1&ID | Mod_2&ID ....  [EDITED below]

43     |   1&1    |  2&2 ....
55     |   1&5    |  2&6 .... 

The Mod numbers are fixed (there are 7 of them).

The concatenation I know how to do, it’s the rearranging values into rows that’s tripping me up.

Any help or direction would be awesome, thanks! 🙂

======================
EDIT:

Hoping that the downvote was lack of clarity than quality of question – let me try to explain better.

This is for an assessment tool being developed in Joomla. Each module (section) gets checked off by a supervisor. When that happens there’s an ID, a UserID, and a ModID recorded (among other data).

That results in a table that looks like this:

ID | UserID | Mod_number

1      43      1
2      43      2
3      43      3 
4      43      4
5      55      1
6      55      2
7      61      2
8      61      4

Each UserID is a user. I need to form this into an array where each row is one user and also contains the ID for each module. I think this presentation might be clearer (skipping the concatenation):

UserID | ID_M1 | ID_M2 | ID_M3 |ID_M4

43     |   1    |   2  |   3   |   4
55     |   5    |   6  |  
61     |        |   7  |       |   8

So that now there’s one unique UserID per row (could be considered a key) with the ID recorded for each Module number. As an array that would probably look something like array(UserID=>array(ID_M1, ID_M2, ID_M3, ID_M4)). But getting that data into this is befuddling me.

Also, if you have other suggestions on structuring the data that would make it easier I’d love to hear – I’m a bit new to php/mysql/Joomla dev and there could be a simpler way of doing this.

Hope that makes more sense, 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-06-04T00:28:44+00:00Added an answer on June 4, 2026 at 12:28 am

    You could write a really ugly query where you GROUP BY UserID and then do some complex string manipulations, I suppose. But you’d be better off just getting this data as is and then restructuring it into an array in PHP.

    $rows; // say this is an array direct from the db with id, user_id, mod_id fields
    $grouped = array(); // we will build this array from your data
    
    foreach ($rows as $row)
    {
        if (!isset($grouped[$row['user_id']]))
        {
            $grouped[$row['user_id']] = array();
        }
    
        $grouped[$row['user_id']]['mod_' . $row['mod_id']] = $row['id'];
    }
    

    Now, when this has run, you should have an array, keyed by user_id, containing arrays keyed like ‘mod_1’, ‘mod_2’, etc. where the value is the ‘id’. I think this is basically what you want.

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

Sidebar

Related Questions

This seems as if it should be easy but I haven't managed to create
In theory this seems easy but I just can't get my head around this...
This seems like it should be really easy but I couln't find an answer
This seems like an easy enough issue but I can't seem to find the
It seems this should be easy but I'm having a lot of difficulty using
This seems like it should be something very easy to do, but every time
This seems like it should be an easy thing to do, but for the
This may seem an easy question, but not to me, also a search has
Not sure if this is possible in git (I haven't found it but I
This seems like a straightforward question, but I haven't had any good answers from

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.