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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T05:55:23+00:00 2026-06-09T05:55:23+00:00

I am trying to insert data from an array in mysql. I have multiple

  • 0

I am trying to insert data from an array in mysql. I have multiple arrays. I have been trying to do something along the lines of this.

foreach ($titles as $title && $descriptions as $description) {
    mysql_query("INSERT INTO `stock` VALUES('', '$title', '$description')");
}

I would like mysql table to look like this.

item_id    title    description
_______________________________

1          title1   description1
2          title2   description2
...

Now I have figured out this won’t work is there any alternative to this. I have seen examples of while loops to do this but i am struggling to understand how that would work.
All help is appreciated 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-09T05:55:26+00:00Added an answer on June 9, 2026 at 5:55 am

    if size of $titles equal size of $descriptions and, you have sequencial arrays, you can do:

    <?php
    $titles = array(
        'foo',
        'bar'
    );
    $descriptions = array(
        'foo description',
        'bar description'
    );
    
    for($i = 0; $i < count($titles); $i++) {
        $title = $titles[$i];
        $description = $descriptions[$i];
    
        mysql_query("INSERT INTO `stock` VALUES('', '$title', '$description')");
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Language: OO PHP 5+ DB: MySQL I am trying to insert data from a
I am trying to take data from one mysql table and insert it in
Im trying to append some JSON data from the last.fm API, I have been
Im trying to append some JSON data from the last.fm API, I have been
I'm new at PHP and am stuck trying to insert data from two arrays
I am trying to insert data from table a to table b (both are
I am trying to insert data from a database into a textarea. I can't
I am trying to insert data from one table that was imported from an
So I am trying to use jQuery to insert data from an ajax call.
I am trying to insert data about an item's price from an HTML form

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.