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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T01:28:47+00:00 2026-05-14T01:28:47+00:00

I have some data, yes, data. This data came from a MySQL query and

  • 0

I have some data, yes, data. This data came from a MySQL query and it will always contain 4 items, always. I want to cache that data in an array table for use later within a web page but I want to keep the keys from the query and separate out each grouping within a multidimensional array. However to save time iterating through the array each time I want to find a given group of data, I want to call the keys of the first array the same as the ID key which is always the first key within each four items.

At the minute I’m using this code:

function mysql_fetch_full_result_array($result)  
{  
$table_result=array();  
$r=0;  
while($row = mysql_fetch_assoc($result)){  
    $arr_row=array();  
    $c=0;  
    while ($c < mysql_num_fields($result)) {        
        $col = mysql_fetch_field($result, $c);   
        $arr_row[$col -> name] = $row[$col -> name];           
        $c++;  
    }     
    $table_result[$r] = $arr_row; 
    $r++;  
}     
return $table_result;  
}  

I’m currently testing this using 3 unique users, so I’m getting three rows back from the query and the data from this function ends up in the format:

 [0]=>  
  . .   [id]   => 1    
  . .   [name] => random name     
  . .   [tel]  => random tel  
  . .   [post] => post code data  
  [1]=>  
  . .   [id]   => 34   
  . .   [name] => random name     
  . .   [tel]  => random tel  
  . .   [post] => post code data  
  [2]=>   
  . .   [id]   => 56   
  . .   [name] => random name      
  . .   [tel]  => random tel  
  . .   [post] => post code data  

So how do I alter the code to instead of the keys [0], [1], [2] give me the output:

  [1]=>  
  . .   [id]   => 1    
  . .   [name] => random name     
  . .   [tel]  => random tel  
  . .   [post] => post code data  
  [34]=>  
  . .   [id]   => 34   
  . .   [name] => random name     
  . .   [tel]  => random tel  
  . .   [post] => post code data  
  [56]=>   
  . .   [id]   => 56   
  . .   [name] => random name      
  . .   [tel]  => random tel  
  . .   [post] => post code data 

I don’t mind if the main array keys are strings of numbers rather than numbers but I’m a bit stuck, I tried changing the $table_result[$r] = $arr_row; part to read $table_result[$result['id']] = $arr_row; but that just outputs an array of one person. I know I need another loop but I’m struggling to work out how to write 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-14T01:28:47+00:00Added an answer on May 14, 2026 at 1:28 am

    Change the line:

    $table_result[$r] = $arr_row; $r++;
    to
    $table_result[$arr_row['id']] = $arr_row;
    

    And I don’t think you need the $r any more.

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

Sidebar

Related Questions

I have some data from log files and would like to group entries by
I have some data and need to create a json file with this structure
I have some data from database coming out in a loop. Each of these
I have some data files from a legacy system that I would like to
basically i have parsed some data from XML into a NSMutableArray that is shared
I have some pretty basic data for a pie chart. Yes: 189.84 (57.03%) No:
I have a problem extrating some data out of this XML file: <?xml version=1.0
I have some problem for decoding image data from base 64 encoded string. I
I have built in some Core Data support into my app from the Core
I want to insert some data to mydatabase.sqlite but I have a problem. There

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.