please delete me please delete me - 1 month ago 8
PHP Question

skip first line of fgetcsv method in php

I have a csv file and i read data from csv file then i want to skip first line of csv file.Which'll contain any header. I am using this code.

while (($emapData = fgetcsv($file, 10000, ",")) !== FALSE)
{
$sql = "INSERT into da1(contact_first, contact_last, contact_email) values('$emapData[0]','$emapData[1]','$emapData[2]')";
mysql_query($sql);

}


When i insert data into th database then header should not to be saved into the database.

Answer

try:

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