4
Contributors
5
Replies
9
Views
5 Years
Discussion Span
Last Post by pritaeas
0

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

0

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

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.