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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T03:14:29+00:00 2026-05-16T03:14:29+00:00

i want to make a new data structure using arrays for this query it

  • 0

i want to make a new data structure using arrays for this query it will be like :

will start with a query and a code example

query http://img85.imageshack.us/img85/170/query.png
i want to make a new data structure using arrays for this query it will be like :

//this is for the first headline
[46] => Array
        (
            [headline_name] => headline 1
            [score] => 50
            [questions] => Array
                (
                    [0] => Array
                        (
                            [question_id] => 136
                            [question_name] => question 3 , headline 1
                            [choice_0] => 0
                            [choice_1] => 0
                            [choice_2] => 0
                            [choice_3] => 0
                            [choice_4] => 0
                        ) ,
                    [1] => Array
                        (
                         ....
                        )
                )
        )

the code that i wrote wanting to achieve this result is :

foreach ($result as $row) {
  $data[$row->headline_id]= array( 
    'headline_name' => $row->headline_name ,
    'score' => $row->score,
  );
  $data[$row->headline_id]['questions'][] = array (
      'question_id'=>$row->question_id ,
      'question_name'=>$row->question_name ,
      'choice_0' => $row->choice_0 ,
      'choice_1' => $row->choice_1 ,
      'choice_2' => $row->choice_2 ,
      'choice_3' => $row->choice_3 ,
      'choice_4' => $row->choice_4             
  );  
}

the problem with it, it only shows the last question in each headline , in each loop in the questions array the array are not appended they overwrite each other


if i want to get it to work i have to delete i have to delete the lines for the score and headline_name , the code will be like this

foreach ($result as $row) {

  $data[$row->headline_id]['questions'][] = array (
      'question_id'=>$row->question_id ,
      'question_name'=>$row->question_name ,
      'choice_0' => $row->choice_0 ,
      'choice_1' => $row->choice_1 ,
      'choice_2' => $row->choice_2 ,
      'choice_3' => $row->choice_3 ,
      'choice_4' => $row->choice_4 
  );  

}

i want a solution to solve it with writing the headline_name and the score in the array

  • 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-16T03:14:29+00:00Added an answer on May 16, 2026 at 3:14 am

    the problem is that you reset the array in the second time when you enter to the loop
    by = ,

    to solve it you need to add a little if

        if(!isset($data[$row->headline_id])) {
          $data[$row->headline_id]= array( 
            'headline_name' => $row->headline_name ,
            'score' => $row->score,
          );
      }
    

    another issue :
    i recommend not to store this fields in this table
    is not normalize ,

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

Sidebar

Ask A Question

Stats

  • Questions 510k
  • Answers 510k
  • 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 Section 2.8 of the code contracts manual specifically states that… May 16, 2026 at 5:04 pm
  • Editorial Team
    Editorial Team added an answer I know Google AppEngine's datastore provides something like this. Even… May 16, 2026 at 5:04 pm
  • Editorial Team
    Editorial Team added an answer I managed to get this to work by adding an… May 16, 2026 at 5:04 pm

Trending Tags

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

Top Members

Related Questions

I'm replacing an old web application with a new one, with different structure. I
This question is about a specific programming problem I am having - I want
My question is best illustrated with a code sample, so let's just start off
I want to create a PDO class for handling data base connections. Here is
I have some basic questions about core data (which I am new to) and
How do I make a QVector (or some other container class) of a dynamic
We're using some C library in our Java project. Several years ago some other
I want to model a kind of FSM(Finite State Machine). I have a sequence
I'm new to NHibernate (+Fluent), and I can't decide on what's the best strategy
I'm learning linked lists, and want to know whether the following program (basically InsertAtEnd

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.