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.
I haven’t included this lines inside
foreachloop , because of that $data is always taking 1st excel file. Not taking further files. This lines are included before foreach loop.The lines are
Now code becomes