如何删除CSV文件中的顶行(列标题)? [英] How do i remove the top line in a CSV file (the coloumn headers)?

查看:942
本文介绍了如何删除CSV文件中的顶行(列标题)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经建立了一个脚本,它将上传一个CSV文件,然后将数据提取到已经创建的表中。我想让它使第一行(列标题)不会插入到表中,但其余的数据将是。

I have put together a script which will upload a CSV file and then extract the data into an already made table. I want to make it so the first line(the column headers) will not be inserted into the table, but the rest of the data will be.

  $fp = fopen($_SESSION['filename'],"r");


while (($data = fgetcsv($fp, 1000, ",")) !== FALSE)

{
    $import="INSERT into csv_table(name,address,age) values('$data[0]','$data[1]','$data[2]')";

    mysql_query($import) or die(mysql_error());

}

fclose($fp);

这是我用来从csv文件中提取数据的代码。

this is the part of the code i use to extract the data from the csv file.

非常感谢您对此事的任何帮助!

Thank You very much for any help with this matter!

推荐答案

下面的 while 循环读取第一行:

Just put the following before the while loop to read the first line:

fgetcsv($fp, 1000, ",");

此后, while

这篇关于如何删除CSV文件中的顶行(列标题)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆