php从excel表获取数据到mysql(如何避免第一行?)

时间:2016-06-25 12:29:05

标签: php mysql excel

我从excel表获取数据并将其存储在数据库中,它正在成功存储数据,但我不希望存储表的第一行,即标题。帮助我完成它。

这是代码:

<?php
if(isset($_POST["submit"]))
{
$file = $_FILES['file']['tmp_name'];
$handle = fopen($file, "r");
$c = 0;
$row = 1;
while(($filesop = fgetcsv($handle, 1000, ",")) !== false)
{
$custid = $filesop[0];
$zone = $filesop[1];
$city = $filesop[2];
$category = $filesop[3];
$focus = $filesop[4];
$customer_type = $filesop[5];
$lead_source = $filesop[6];
$exhibition = $filesop[7];
$organization_name = $filesop[8];
$assign_to = $filesop[9];
$description = $filesop[10];
$division = $filesop[11];
$product = $filesop[12];
$grade = $filesop[13];
$potential = $filesop[14];
$firstname = $filesop[15];
$lastname = $filesop[16];
$designation = $filesop[17];
$mobile = $filesop[18];
$primary_phone = $filesop[19];
$primary_email = $filesop[20];
$address_type = $filesop[21];
$address1 = $filesop[22];
$address2 = $filesop[23];
$state = $filesop[24];
$country = $filesop[25];


$hgf = "INSERT INTO temp_const set custid='$name', zone='$zone',     city='$city', category='$category', focus='$focus',     customer_type='$customer_type', lead_source='$lead_source',     exhibition='$exhibition', organization_name='$organization_name',     assign_to='$assign_to', description='$description', division='$division',     product='$product', grade='$grade', potential='$potential',     firstname='$firstname', lastname='$lastname', designation='$designation',     mobile='$mobile', primary_phone='$primary_phone',     primary_email='$primary_email', address_type='$address_type',     address1='$address1', address2='$address2', state='$state', country='$country'     ";

$sql = mysql_query($hgf);
$c = $c + 1;
}

if($sql){
echo "You database has imported successfully. You have inserted ". $c     ."recoreds";
}else{
echo " Sorry! There is some problem.";
}

}
?>

1 个答案:

答案 0 :(得分:0)

$flag = true;
while (($emapData = fgetcsv($file, 10000, ",")) !== FALSE)
if($flag) { $flag = false; continue; }
//your code

我希望它会有所帮助