DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   PHP (http://www.daniweb.com/forums/forum17.html)
-   -   read second line or record of csv file (http://www.daniweb.com/forums/thread84275.html)

redcoder07 Jul 23rd, 2007 12:43 pm
read second line or record of csv file
 
Anyone know how to read the second line from a csv file using PHP? I need the read the second line from the csv file and import into mysql

Ezzaral Jul 23rd, 2007 1:06 pm
Re: read second line or record of csv file
 
Here's a tutorial that should get you there:
http://www.goodphptutorials.com/track/62

redcoder07 Jul 23rd, 2007 1:28 pm
Re: read second line or record of csv file
 
Is there mentioned how to read second row onwards or any particular row onwards from csv file? I try look at that wrbsite but couldn't find it.

Ezzaral Jul 23rd, 2007 1:48 pm
Re: read second line or record of csv file
 
Quote:

Originally Posted by redcoder07 (Post 408294)
Is there mentioned how to read second row onwards or any particular row onwards from csv file? I try look at that wrbsite but couldn't find it.

Right in the middle of the table of contents there is a link to the section "Working with CSV".

redcoder07 Jul 23rd, 2007 1:57 pm
Re: read second line or record of csv file
 
Yeah, thats the one i searched for, but couldn't get the answer

Ezzaral Jul 23rd, 2007 2:07 pm
Re: read second line or record of csv file
 
This code opens and reads a line into $line until there are no more lines:
<?php
  $fp = fopen('file.csv', 'r');
  while (!feof($fp)) {
    $line = fgetcsv($fp, 4096);
    echo $line; // do whatever you need here
  }
  fclose($fp);
?>

file_get() can be used as well, to load each line into an array, if you prefer to work with it like that.

redcoder07 Jul 24th, 2007 4:58 am
Re: read second line or record of csv file
 
Alright, i got you now. meaning i can do some skipping code to replace
echo $line; // do whatever you need here

with some code that read the string is not equal to the column name in the csv file and proceed to insert.

Thanks for your help. Really appreciated

premmaneesh May 4th, 2009 8:10 am
Re: read second line or record of csv file
 
i am also confused how to get a specific row from a csv file, is anyone know how to do it ?

Ezzaral May 4th, 2009 2:36 pm
Re: read second line or record of csv file
 
Did you read any of the posts above? Did you understand them? If not, what didn't you understand? You need to learn how to ask questions.


All times are GMT -4. The time now is 5:53 am.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC