User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 391,631 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,783 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 1780 | 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: 2,599
Reputation: Ezzaral is just really nice Ezzaral is just really nice Ezzaral is just really nice Ezzaral is just really nice Ezzaral is just really nice 
Rep Power: 11
Solved Threads: 257
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Posting Maven

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: 2,599
Reputation: Ezzaral is just really nice Ezzaral is just really nice Ezzaral is just really nice Ezzaral is just really nice Ezzaral is just really nice 
Rep Power: 11
Solved Threads: 257
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Posting Maven

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: 2,599
Reputation: Ezzaral is just really nice Ezzaral is just really nice Ezzaral is just really nice Ezzaral is just really nice Ezzaral is just really nice 
Rep Power: 11
Solved Threads: 257
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Posting Maven

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 1: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)

 

DaniWeb PHP Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the PHP Forum

All times are GMT -4. The time now is 1:00 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC