douruobokui58233
douruobokui58233
2016-06-25 12:29
浏览 110
已采纳

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

i am getting data from excel sheet and storing it in database it is storing the data successfully but i dont want store the first row of the table which is the header. help me out to get it done.

this is the code:

<?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条回答 默认 最新

  • du6jws6975
    du6jws6975 2016-06-25 12:35
    已采纳
    $flag = true;
    while (($emapData = fgetcsv($file, 10000, ",")) !== FALSE)
    if($flag) { $flag = false; continue; }
    //your code
    

    i hope it will be helpful

    点赞 评论

相关推荐