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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T10:14:31+00:00 2026-06-12T10:14:31+00:00

I am reading a bunch of excel files and inserting their data inside database.

  • 0

I am reading a bunch of excel files and inserting their data inside database. The queries are all working correctly. Only problem is if an author is present in first excel file its entry is also showing in other excel file also. This is my code.

$array = array(
1=>"abc",
2=>"def",
3=>"age");

foreach ($array as $key=>$val) {
    $file = $array[$key].'.xls';
    $data->read($file);
    $ID = $key;
    for ($i = 1; $i <= $data->sheets[0]['numRows']; $i++) {
        $a = addslashes($data->sheets[0]['cells'][$i][1]);
        if($a == "Ali")
        {
             echo $a."=>".$ID." ".$i."<br>";
        }
    }
}

The desired output is

abc.xls
Ali=>1 282
def.xls
age.xls

and the output coming is

abc.xls
Ali=>1 282
def.xls
Ali=>2 282
age.xls
Ali=>3 282

Can anybody tell me where is mistake in this code. Any help will be appreciate..

NOTE The number of rows present in excel sheet are 100.

  • 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-12T10:14:32+00:00Added an answer on June 12, 2026 at 10:14 am

    I haven’t included this lines inside foreach loop , because of that $data is always taking 1st excel file. Not taking further files. This lines are included before foreach loop.

    The lines are

    $data = new Spreadsheet_Excel_Reader();
    $data->setOutputEncoding('utf-8');
    

    Now code becomes

    foreach ($array as $key=>$val) {
        $data = new Spreadsheet_Excel_Reader();
        $data->setOutputEncoding('utf-8');
        $file = $array[$key].'.xls';
        $data->read($file);
        $ID = $key;
        for ($i = 1; $i <= $data->sheets[0]['numRows']; $i++) {
           $a = addslashes($data->sheets[0]['cells'][$i][1]);
           if($a == "Ali")
           {
             echo $a."=>".$ID." ".$i."<br>";
           }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am reading in a bunch of XML files. If the file only contains
I have a problem with reading a bunch of files using the following C#
I've got a bunch of csv files that I'm reading into R and including
All, I'm working on an application that allows authorized users to upload Excel spreadsheets
I'm working with a large bunch of RRD-files, where I have to query the
I'm reading in and parsing some data. Basically, the data is a bunch of
So i am reading a bunch of log files. Most of them are good
We have a bunch of data on S3 (images) but just started reading about
I've got a project where I'm reading data from an Excel worksheet and saving
So I'm reading a bunch of PHP files trying to find each accurance of

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.