PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, August 29, 2022

[FIXED] How do i remove the top line in a CSV file (the coloumn headers)?

 August 29, 2022     csv, php     No comments   

Issue

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

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!


Solution

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

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

Thereafter the while loop starts with the second line instead.



Answered By - Gumbo
Answer Checked By - Dawn Plyler (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing