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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T21:15:39+00:00 2026-06-09T21:15:39+00:00

I am importing data from csv file so I used that code <?php $path

  • 0

I am importing data from csv file so I used that code

<?php
$path = "Export.csv";
$row = 1;
if (($handle = fopen($path, "r")) !== FALSE) {
    while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
        $row++;
        $data_entries[] = $data ;


    }
    fclose($handle);
}
 echo"<pre>";
 print_r($data_entries);
 echo"</pre>";
?>

and my array output like that my first array showing column names after that all array showing value so i want to insert value base on first array column names

 Array
 (
  [0] => Array
    (
        [0] => Type
        [1] => PinCode
        [2] => APN
        [3] => County
    )
  [1] => Array
    (
        [0] => Auction
        [1] => 503082537
        [2] => 502-052-002
        [3] => United States of America
    )
  [2] => Array
    (
        [0] => Auction
        [1] => 21596378
        [2] => 628-202-038
        [3] => Australia
     )
 )
  • 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-09T21:15:41+00:00Added an answer on June 9, 2026 at 9:15 pm

    Try the below code :

    //extract the column names
    $fields = array_shift($data_entries);
    $values = array();
    
    // Append the values
    foreach($data_entries as $value){
       $values[]="('{$value[0]}', '{$value[1]}', '{$value[2]}', '{$value[3]}' )";
    }
    
    // Build the SQL
    $sql = "INSERT INTO `TABLE_NAME` (" . implode(',' , $fields) . ") values " . implode(',', $values);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a web form used for importing data from a CSV file. It
I'm importing data from a CSV file that comes from excel, but i can't
I'm importing some data from a CSV file, and numbers that are larger than
I am importing data from csv file, sometimes there are column headers and some
I am importing data from a CSV file into a postgreSQL table. The table
I have some questions about importing data from Excel/CSV File into SQL Server. Let
I am importing data from a CSV file. One of the fields has an
I'm importing data from a CSV that contains approx 350 columns. This CSV import
I am importing data from a CSV file using fgetcsv(), which yields an array
I am using PHP to expose vehicle GPS data from a CSV file. This

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.