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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T21:03:12+00:00 2026-06-01T21:03:12+00:00

I am wondering the best way to insert a multidimensional array of values into

  • 0

I am wondering the best way to insert a multidimensional array of values into a database – particularly two tables? I created the following foreach loop which creates a query that will insert all the records into one table:

foreach($newPosts as $value) {
            if(!isset($postQuery)) {
                $postQuery = "INSERT INTO posts (primay_key, col1, col2, col3, col4) VALUES ('$value[0]', FROM_UNIXTIME($value[4]), '$value[2]', '$value[1]', '$value[3]')";
            } else {
                $postQuery .= "('$value[0]', FROM_UNIXTIME($value[4]), '$value[2]', '$value[1]', '$value[3]')";
            }
    }

I want to store one of the values in a separate table since the value is particularly large and the row is formatted as Longtext. This value is also rarely called upon when querying the database. I am assuming that moving it into a second table will increase the query speed of the first table? Is that correct?

If I move this value into a second table, I want to link the tables with the primary_key from the first table which is an auto-increment value. How do I loop through this multidimensional array and insert my data into both tables, while inserting the primary_key of the first table into the second? I know I can use LAST_INSERT_ID() if I am running each query one at a time. Some updates will insert hundreds of rows though, so I don’t want to do that.

Thanks in advance!

  • 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-01T21:03:14+00:00Added an answer on June 1, 2026 at 9:03 pm

    I am assuming that moving it into a second table will increase the query speed of the first table? Is that correct?

    Not necessarily. It’s only going to affect performance

    • if the large column is indexed (which is unlikely since MySQL limits the size of indexed fields)
    • if your queries routinely do full table scans
    • if the value is null in a large proportion of cases (more than about a third)

    As you say, you lose the benefits of multi-inserts by splitting it into 2 tables. So your only options are, as you suggest, to insert one record at a time and read back the insert id or (with lots of code an complexity) use a sequence generator and preallocate multiple record ids.

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

Sidebar

Related Questions

I am wondering what's the best way to insert customization hooks into my application.
I was wondering what the best way is for storing and retrieving session values
I am wondering the best way to store html templates in a database where
Was wondering the best way to do the following: I am uploading a file
I was wondering the best way to upload file to a web server in
Just wondering whats the best way to test Python CGI while developing a site?
Just wondering what the best way to build a NSPredicate is if some filters
I was wondering what the best way to use transations with the entity framework.
I am wondering whats the best way to programmatically make rounded corners for images.
I'm wondering how the best way to build a way to interface with Yahoo

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.