我从excel表中获取数据并将其放入表中。 但我的要求是,我想从第2行开始获取数据,第1行是用户提交数据的标题。 请帮忙。
使用我拥有的代码,它可以从第1行开始获取数据。
$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=1;$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]);
$variety= mysqli_real_escape_string($connection,$data->sheets[$i][cells][$j][5]);
$tender = mysqli_real_escape_string($connection,$data->sheets[$i][cells][$j][6]);
$subtype = mysqli_real_escape_string($connection,$data->sheets[$i][cells][$j][7]);
$type = mysqli_real_escape_string($connection,$data->sheets[$i][cells][$j][8]);
$query = "insert into submit_form(name,lab,submission,title,patient,age,gender,ethnic,cancer,sample,instrument,instrumenttype,attach) values('".$_POST['name']."','".$_POST['dept']."','".$_POST['submission']."','".$_POST['title']."','".$eid."','".$age."','".$gender."','".$ethnic."','".$variety."','".$tender."','".$subtype."','".$type."','1')";
mysqli_query($connection,$query);
$html.="</tr>";
}
}
}
$html.="</table>";
header("location: submit.php?success=1");
}
}