Reputation: 73
This is my mydata.xls
Excel sheet image:
my php code:
<?php
// include class file
include("Excel/reader.php");
// initialize reader object
$excel = new Spreadsheet_Excel_Reader();
// read spreadsheet data...
$excel->read('mydata.xls');
// iterate over Excel sheet cells and save to database table//////////
$x=2;
while($x<=$excel->sheets[0]['numRows']) {
$y=1;
while($y<=$excel->sheets[0]['numCols']) {
//save data to an array..
$z=$y-1;
$data[$z]=$excel->sheets[0]['cells'][$x][$y];
$y++;
} //end 2 while
//store array values to variables..
$st_id=$data[0];
$marks=$data[1];
$co_type=$data[2];
$status=$data[3];
echo $st_id."</br>";
$x++;
}//end 1 while
?>
Output Image:
problem: how to stop showing last row repeated.....????????????? last row value print many no of times how to stop that?? plzz tell the code error & how to fix this problem????
Upvotes: 1
Views: 714
Reputation: 360702
You're pulling data out of a 2-dimensional spreadsheet, then assign that data to a 1-dimensional array:
$data[$z]=$excel->sheets[0]['cells'][$x][$y];
^^--- 1D array
You then always echo the SAME cells:
$st_id=$data[0];
^---hard coded
Not sure what you're trying to accomplish here at all.
Upvotes: 2