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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T20:47:08+00:00 2026-06-12T20:47:08+00:00

I am currently working on reading a excel using php and storing those records

  • 0

I am currently working on reading a excel using php and storing those records in mysql.I came across PHPExcel,a bunch of very nice plugin classes which can very easily help to achive it.I tried to search through but did not something similar to my use case.Also,not very good at object oriented PHP and I am short of time in doing this.

    First Name  Last Name   Nationality Gender  Date of Birth   Time of Birth   Date/Time   PHP Coder   Sanity %Age

Above are my sample database columns and First row of my excel sheet.I want to match the column names of my rows before inserting them to database.
My code till now gives me a 2 dimensional array in which I get the column names and values.The reason I want to check the column name before inserting is that,my excels can be in any order of the column names.
I used exampleReader01 in the package and some SO reference to achieve this.

  $headingsArray = $objWorksheet->rangeToArray('A1:'.$highestColumn.'1',null, true, true, true);
  $headingsArray = $headingsArray[1];
  $r = -1;
  $namedDataArray = array();
  for ($row = 2; $row <= $highestRow; ++$row) {
  $dataRow = $objWorksheet->rangeToArray('A'.$row.':'.$highestColumn.$row,null, true, true, true);
  if ((isset($dataRow[$row]['A'])) && ($dataRow[$row]['A'] > '')) {
       ++$r;
  foreach($headingsArray as $columnKey => $columnHeading){
      $namedDataArray[$r][$columnHeading] = $dataRow[$row][$columnKey];
    }
  }
}

Now I want some help how can I insert this in the right column.
My array is like this

Array
(
 [0] => Array
    (
        [First Name] => Mark
        [Last Name] => Baker
        [Nationality] => British
        [Gender] => M
        [Date of Birth] => 19-Dec-60
        [Time of Birth] => 1:30
        [Date/Time] => 22269.0625
        [PHP Coder] => 1
        [Sanity %Age] => 32%
    )

[1] => Array
    (
        [First Name] => Toni
        [Last Name] => Baker
        [Nationality] => British
        [Gender] => F
        [Date of Birth] => 24-Nov-50
        [Time of Birth] => 20:00
        [Date/Time] => 18591.83333
        [PHP Coder] => 
        [Sanity %Age] => 95%
    )

[2] => Array
    (
        [First Name] => Rachel
        [Last Name] => Baker
        [Nationality] => British
        [Gender] => F
        [Date of Birth] => 7-Dec-82
        [Time of Birth] => 0:15
        [Date/Time] => 30292.01042
        [PHP Coder] => 
        [Sanity %Age] => 100%
    )

 )

Hope I am clear.
Thanks for your time.

  • 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-12T20:47:09+00:00Added an answer on June 12, 2026 at 8:47 pm

    If I can assume that your Excel column header names never change, why not simply use a mapping array?

    $dbMapping = array(
        'col1' => header1,
        'col2' => header2,
         ..
        'colN' => headerN
    );
    

    So when you’re ready to insert to the database, you iterate through each row with the column header names you already have in your 2D array and pass it into your mapping array i.e. $dbMapping[‘col1’] and that will get you your header name and you can grab the correct row value.

    psuedo

     foreach ($rows as $row) {
         insert into col1, col2, ... colN
           values ($rows[$dbMapping['col1']], $rows[$dbMapping['col2']], ...
     }
    

    Of course it would be in your best interest to use parameterized values.

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

Sidebar

Related Questions

I am currently working on an android application which requires reading data from bluetooth
I'm currently working on a PowerShell script to analyse VPN traffic by reading the
I'm currently reading Learning Rails 3. I'm working on an example where you can
So I'm currently working on an ePub reader application, and I've been reading through
I am currently working on a project for traversing an excel document and inserting
Thanks for reading. I'm currently working on a database of about 10 entities for
I'm currently working on a project trying to update a page reading from an
I'm currently working on a GWT project. The thing is, I find very hard
I'm currently working on a project that involves a lot of text file reading.
I'm currently working on Image stitching using OpenCV 2.3.1 on Visual Studio 2010, but

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.