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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T17:11:37+00:00 2026-06-11T17:11:37+00:00

I have the following result set ID SUBID DATA 1 0 Question1 1 1

  • 0

I have the following result set

ID SUBID DATA

1 0  Question1

1 1  Option1

1 2  Option2

2 0  Question1

2 1  Option1

2 2  Option2
...

I really want an array that looks like this

$item_data[1][1] = ID 1
$item_data[1][2] = Question1 <br> Option1 <br> Option2

$item_data[2][1] = ID 2
$item_data[2][2] = Question2 <br> Option1 <br> Option2

I have racked my brains trying loops within loops and string concatination but I just cant get my result set to look like this

Im trying to get it into one array so I can then out put the data – its important that the data stays together but different ID’s are selerate from each other

SubID is not used – the table looks like this due to db design which I cant change

select iseg.item_id ,iseg.item_subid, iseg.item_data from items i
    inner join  item_data iseg on iseg.item_id = i.item_id
union all
select iseg.item_stg_id ,iseg.item_subid, iseg.item_data from items_stg i
    inner join  item_data_stg iseg on iseg.item_stg_id = i.item_stg_id
    order by iseg.item_id desc, iseg.item_subid

The Item data needs parsing in PHP first before concatination

  • 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-11T17:11:39+00:00Added an answer on June 11, 2026 at 5:11 pm

    Assuming $resultset is your mysql result set, you could do as follows:

    while( $row = mysql_fetch_array($resulset)) {
        if (!isset($arr[$row['ID']])) {
           $arr[$row['ID']][1]  = 'ID ' . $row['ID'];
           $arr[$row['ID']][2]  = 'Im data '.$row['ID'].' <br>';
        } else {
           $arr[$row['ID']][2] .= 'Im data '.$row['ID'].' <br>';
        } 
    }
    foreach ($arr as &$ar) { //remove last <br> from elements
        $ar[2] = substr($ar[2], 0, -4);
    }
    
    var_dump($arr); //to check the output
    

    In your example there are only three rows for each ID, but my above code allows for any number of rows with same ID, so that could be important if that case could happen.

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

Sidebar

Related Questions

I have the following result set that was generated as the result of a
Provided that I have the following result set from a mysql database table: +----+------+-------+
I have to parse the following data {ResultSet:{Query:microsec fin,Result: [{symbol:MICROSE_a.NS,name: MICROSEC FIN SERV LTD
I have the following code which definitely returns a proper data result if I
I have the following result set from a join of three tables, an articles
I have a query with a self join that looks like this, select t1.
For example I have the following query (see How to produce a result set
i have a following format of the result set in sql server TagId Tag
I have the following query that looks for transactions that cancel themselves out from
How to convert row into column.I have following result set. UserID VendorName QuestionText AnswerText

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.