douruobokui58233 2016-06-25 12:29 采纳率: 0%
浏览 135
已采纳

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 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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 buildozer打包kivy app失败
  • ¥30 在vs2022里运行python代码
  • ¥15 不同尺寸货物如何寻找合适的包装箱型谱
  • ¥15 求解 yolo算法问题
  • ¥15 虚拟机打包apk出现错误
  • ¥15 用visual studi code完成html页面
  • ¥15 聚类分析或者python进行数据分析
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复