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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T12:56:39+00:00 2026-06-04T12:56:39+00:00

Here I have a MySQL database and I need to retrieve many rows. I

  • 0

Here I have a MySQL database and I need to retrieve many rows.

I need the data to stack up in one array:

$query_sel_node  = "SELECT * FROM $table_name";                 
$result_data = mysql_query($query_sel_node);

$data_rec = array("data" => array(), "data_h" => array(), "file" => array(), "ptr" => array(), "name" => array());
while($data_fetched = mysql_fetch_assoc($result_data))
                {   
                    array_push($data_rec["data_h"], $data_fetched['data_h']);
                    array_push($data_rec["data"], $data_fetched['data']);
                    array_push($data_rec["file"], $data_fetched['m_file_thumb']);
                    array_push($data_rec["ptr"], $data_fetched['m_pointer']);
                    array_push($data_rec["name"], $data_fetched['m_name']);
                }

now, i’ve added alot of columns to my table , which means i would need to array_push() for every single column i made.

is there a easier way that i can do this with fewer lines of code?

what i’m looking for is this:

i have a mysql table with column {m_data, m_name, m_file}
and i have several rows of data

now i need to get them into array

my array will use the column names an the key,
then i’ll store my row data into each key

  • 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-04T12:56:40+00:00Added an answer on June 4, 2026 at 12:56 pm

    First, get all of the column names from the desired table:

    SELECT
        COLUMN_NAME
    FROM INFORMATION_SCHEMA.COLUMNS
    WHERE
        table_name = '$table_name'
    

    Build the array ($table) with the column names and assign an empty array to each one (for the data):

    $columns_query = mysql_query($the_above_query);
    $table = array();
    while ($column = mysql_fetch_row($columns_query))
        $table[$column[0]] = array();
    

    Fetch the data for each column and insert it into the $table array:

    foreach (array_keys($table) as $column)
    {
        $query_sel_node  = "SELECT $column FROM $table_name";                 
        $result_data = mysql_query($query_sel_node);
    
        while ($data = mysql_fetch_row($result_data))
            $table[$column][] = $data[0];
    }
    

    Now, $table will contain the exact structure and data that the table $table_name does.

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

Sidebar

Related Questions

PHP mysql database I have created a follow on question to this one here
I need to retrieve data from several rows and then insert the results into
I'm using this php to fetch data from my mysql database: $wpdb->get_var(select count(*) from
I need help with displaying images from a MySQL database. What I have is
I need help with displaying images from a MySQL database. What I have is
I have a MySQL/Rails app that needs search. Here's some info about the data:
So here's the problem. I have data in a MySQL DB as text. The
Here I have a simple php script which displays some values from a database
I have a MySQL database with a date_of_birth field. The data stored in this
I have already created a report using list of data from my database. i

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.