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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T01:08:48+00:00 2026-05-31T01:08:48+00:00

I am iterating over data dynamically. The data contains three fields that I want

  • 0

I am iterating over data dynamically. The data contains three fields that I want to insert into an array.. Array(field1,field2,field3)..and then insert that array into another array (nest it). Then nest another array into the main array. The problem is that i dont know how to do it so that I get one array out of the loop that will contain all the nested arrays.

$myArray=array();
  while($row=mysql_fetch_array($result))
    {
        $myArray+= Array(field1,field2,field3);
    }

How do you add them dynamically..I know I do it the wrong way..But how do you do it?!

  • 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-31T01:08:49+00:00Added an answer on May 31, 2026 at 1:08 am
    while ($row = mysql_fetch_assoc($result1) {
        $myArray[] = array($row['field1'], $row['field2'], $row['field3']);
    }
    

    If you want to add the whole content of each row, i.e. every field in a row, you can just use

    while ($row = mysql_fetch_assoc($result1) {
        $myArray[] = $row;
    }
    

    or just this single line:

    while ($myArray[] = mysql_fetch_assoc($result));
    

    Then you can access e.g. field2 of row 5 with $myArray[4][‘field2’]

    In your question you use the function mysql_fetch_array. Please use mysql_fetch_assoc as this is most certainly the better way. mysql_fetch_array returns every value twice, once with a numeric index (e.g. 1, but note that this depends on the order of the queried fields in your query!), once with an associative index. mysql_fetch_assoc only returns each value once with its associative index (e.g. ‘field2’).

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

Sidebar

Related Questions

I am iterating over an array which contains filenames. For each of them, I
I am iterating over a list and I want to print out the index
Is there a performance hit when iterating over object attributes vs. iterating an array?
I have the following issue related to iterating over an associative array of strings
Is there a better shorter way than iterating over the array? int[] arr =
I am iterating over data on the Electrical Tables sheet and creating shapes on
When iterating over elements of a vector it is preferred to use iterators instead
If I am iterating over each file using : @echo off FOR %%f IN
I'm iterating over a JRE Collection which enforces the fail-fast iterator concept, and thus
What is the correct way of iterating over a vector in C++? Consider these

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.