My purpose is to read an excel (.xls) file and store it in the database as well as show the inputs of excel file in the browser.
I am facing problem while reading the file. I have integrated Excelfilereader.php
The program reads the excel file but while printing its output in (excel file content) in the browser, data print in zig-zag way.
Example:
studentid name class school course address [name of fields]
In Browser, the same fields are printed, but the data of studentID is printed under the name, data of name prints under class, but rest all are printed as it is. In first two columns are printed unaligned.
Code used to call Excelreader.php:
[mysql_query("insert into submit_form(parent_id,name,lab,submission,title,sampletype,file) values('','".$_POST['name']."','".$_POST['lab']."','".$_POST['submission']."','".$_POST['title']."','".$_POST['sampletype']."','".$uploadfile."')");
$insertid=mysql_insert_id();
$data = new Spreadsheet_Excel_Reader($_FILES['uploadfile']['name']);
//echo "Total Sheets in this xls file: ".count($data->sheets)."<br /><br />";
$html="<table border='1'>";
for($i=0;$i<count($data->sheets);$i++) // Loop to get all sheets in a file.
{
if(count($data->sheets[$i][cells])>0) // checking sheet not empty
{
//echo "Sheet $i:<br /><br />Total rows in sheet $i ".count($data->sheets[$i][cells])."<br />";
for($j=2;$j<=count($data->sheets[$i][cells]);$j++) // loop used to get each row of the sheet
{
$html.="<tr>";
for($k=1;$k<=count($data->sheets[$i][cells][$j]);$k++) // This loop is created to get data in a table format.
{
$html.="<td>";
$html.=$data->sheets[$i][cells][$j][$k];
$html.="</td>";
}
$data->sheets[$i][cells][$j][1];
$eid = $eid = mysqli_real_escape_string($connection,$data->sheets[$i][cells][$j][1]);
$age = mysqli_real_escape_string($connection,$data->sheets[$i][cells][$j][2]);
$gender = mysqli_real_escape_string($connection,$data->sheets[$i][cells][$j][3]);
$ethnic = mysqli_real_escape_string($connection,$data->sheets[$i][cells][$j][4]);
$cancer = mysqli_real_escape_string($connection,$data->sheets[$i][cells][$j][5]);
$sample = mysqli_real_escape_string($connection,$data->sheets[$i][cells][$j][6]);
$instrument = mysqli_real_escape_string($connection,$data->sheets[$i][cells][$j][7]);
$instrumenttype = mysqli_real_escape_string($connection,$data->sheets[$i][cells][$j][8]);
$query = "insert into submit_form(parent_id,name,lab,submission,title,patient,age,gender,ethnic,cancer,sample,instrument,instrumenttype,attach,sampletype,file) values('".$insertid."','".$_POST['name']."','".$_POST['lab']."','".$_POST['submission']."','".$_POST['title']."','".$eid."','".$age."','".$gender."','".$ethnic."','".$cancer."','".$sample."','".$instrument."','".$instrumenttype."','1','".$_POST['sampletype']."','".$uploadfile."')";
mysqli_query($connection,$query);
$html.="</tr>";
}
}][2]