RSS Forums RSS
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 2279 | Replies: 6
Reply
Join Date: May 2007
Posts: 5
Reputation: redcoder07 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
redcoder07 redcoder07 is offline Offline
Newbie Poster

read second line or record of csv file

  #1  
Jul 23rd, 2007
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
AddThis Social Bookmark Button
Reply With Quote  
Join Date: May 2007
Location: USA
Posts: 3,176
Reputation: Ezzaral is a splendid one to behold Ezzaral is a splendid one to behold Ezzaral is a splendid one to behold Ezzaral is a splendid one to behold Ezzaral is a splendid one to behold Ezzaral is a splendid one to behold Ezzaral is a splendid one to behold 
Rep Power: 15
Solved Threads: 314
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Posting Sensei

Re: read second line or record of csv file

  #2  
Jul 23rd, 2007
Here's a tutorial that should get you there:
http://www.goodphptutorials.com/track/62
Reply With Quote  
Join Date: May 2007
Posts: 5
Reputation: redcoder07 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
redcoder07 redcoder07 is offline Offline
Newbie Poster

Re: read second line or record of csv file

  #3  
Jul 23rd, 2007
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.
Reply With Quote  
Join Date: May 2007
Location: USA
Posts: 3,176
Reputation: Ezzaral is a splendid one to behold Ezzaral is a splendid one to behold Ezzaral is a splendid one to behold Ezzaral is a splendid one to behold Ezzaral is a splendid one to behold Ezzaral is a splendid one to behold Ezzaral is a splendid one to behold 
Rep Power: 15
Solved Threads: 314
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Posting Sensei

Re: read second line or record of csv file

  #4  
Jul 23rd, 2007
Originally Posted by redcoder07 View Post
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".
Reply With Quote  
Join Date: May 2007
Posts: 5
Reputation: redcoder07 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
redcoder07 redcoder07 is offline Offline
Newbie Poster

Re: read second line or record of csv file

  #5  
Jul 23rd, 2007
Yeah, thats the one i searched for, but couldn't get the answer
Reply With Quote  
Join Date: May 2007
Location: USA
Posts: 3,176
Reputation: Ezzaral is a splendid one to behold Ezzaral is a splendid one to behold Ezzaral is a splendid one to behold Ezzaral is a splendid one to behold Ezzaral is a splendid one to behold Ezzaral is a splendid one to behold Ezzaral is a splendid one to behold 
Rep Power: 15
Solved Threads: 314
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Posting Sensei

Re: read second line or record of csv file

  #6  
Jul 23rd, 2007
This code opens and reads a line into $line until there are no more lines:
  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.
Reply With Quote  
Join Date: May 2007
Posts: 5
Reputation: redcoder07 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
redcoder07 redcoder07 is offline Offline
Newbie Poster

Re: read second line or record of csv file

  #7  
Jul 24th, 2007
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
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 5:33 am.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC