Hi,
i am inserting data from CSV file in mysql.
I am trying to skip ist row of CSV file as it contains headings.
need suggestions??

Member Avatar

@jacob21

i am inserting data from CSV file in mysql.
I am trying to skip ist row of CSV file as it contains headings.
need suggestions??

Can you post the code so it will easier to see what you are doing.

How are you importing the CSV (some code is preferred)?

Are you passing the entire CSV file to MySQL or are you reading it line by line in a while loop? If reading line by line, then it's easy: do one read before the while loop to get the first row, then run the loop normally.

<?php
$csvHeadings = NULL;  // Will store the first row
$csvEntries  = array();  // Will store everything EXCEPT the first row
$handle      = fopen($filePath, 'r');

// Get first row
$csvHeadings = fgetcsv($handle, 1024); // 1024 must be >= length of first row

// Get all other rows
while (!feof($handle) ) {
    $csvEntries[] = fgetcsv($handle, 1024); // 1024 must be >= longest line in file
}

fclose($handle);

// $csvEntries is now an array of arrays containing the data from the CSV file after the first row.

Hi,
I read from my csv and getting below array

Array ( [0] => CBSE [1] => Sourav [2] => Maths ) Array ( [0] => HBSE [1] => pankaj [2] => drupal ) Array ( [0] => GBSE [1] => Vinod [2] => PHP ) Array ( [0] => abcd [1] => SDS [2] => DFS )

I am trying to extract like below i.e end of the csv
[0][0] [array 1][CBSE]
[0][1] [array 1][sourav]
[0][2] [array 1][maths]
[0][3] ........

[1][0] [array 1][HBSE]
[1][1] [array 1][Pankaj]
[1][2] [array 1][drupal]

need suggestions

The array you get and what you'd like are identical.