943,717 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 9126
  • PHP RSS
Jul 23rd, 2007
0

read second line or record of csv file

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
redcoder07 is offline Offline
5 posts
since May 2007
Jul 23rd, 2007
0

Re: read second line or record of csv file

Here's a tutorial that should get you there:
http://www.goodphptutorials.com/track/62
Moderator
Featured Poster
Reputation Points: 3239
Solved Threads: 838
Posting Genius
Ezzaral is offline Offline
6,760 posts
since May 2007
Jul 23rd, 2007
0

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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
redcoder07 is offline Offline
5 posts
since May 2007
Jul 23rd, 2007
0

Re: read second line or record of csv file

Click to Expand / Collapse  Quote originally posted by redcoder07 ...
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".
Moderator
Featured Poster
Reputation Points: 3239
Solved Threads: 838
Posting Genius
Ezzaral is offline Offline
6,760 posts
since May 2007
Jul 23rd, 2007
0

Re: read second line or record of csv file

Yeah, thats the one i searched for, but couldn't get the answer
Reputation Points: 10
Solved Threads: 0
Newbie Poster
redcoder07 is offline Offline
5 posts
since May 2007
Jul 23rd, 2007
0

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 Syntax (Toggle Plain Text)
  1. <?php
  2. $fp = fopen('file.csv', 'r');
  3. while (!feof($fp)) {
  4. $line = fgetcsv($fp, 4096);
  5. echo $line; // do whatever you need here
  6. }
  7. fclose($fp);
  8. ?>

file_get() can be used as well, to load each line into an array, if you prefer to work with it like that.
Last edited by Ezzaral; Jul 23rd, 2007 at 2:08 pm.
Moderator
Featured Poster
Reputation Points: 3239
Solved Threads: 838
Posting Genius
Ezzaral is offline Offline
6,760 posts
since May 2007
Jul 24th, 2007
0

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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
redcoder07 is offline Offline
5 posts
since May 2007
May 4th, 2009
0

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 ?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
premmaneesh is offline Offline
1 posts
since May 2009
May 4th, 2009
0

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.
Moderator
Featured Poster
Reputation Points: 3239
Solved Threads: 838
Posting Genius
Ezzaral is offline Offline
6,760 posts
since May 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Need function to calculate normal cumulative density function please
Next Thread in PHP Forum Timeline: complex problems





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC