[SOLVED] Quick Question...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ibanez270dx
Forum Commoner
Posts: 74
Joined: Thu Jul 27, 2006 12:06 pm
Location: Everywhere, California

[SOLVED] Quick Question...

Post by ibanez270dx »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hello Everyone,
 This is probably a really simple problem, but I'm trying to parse a CSV file and everything works perfectly... except I want to start the read at line 2 and completely omit line 1. My code look like this:

Code: Select all

$row = 1;
$handle = fopen("test.csv", "r");
while (($data = fgetcsv($handle, 1500, ",")) !== FALSE) 
   {
    $num = count($data);

    $display .= "<tr><td><font size=2 face=arial>$data[0]</td>
	 	     <td><font size=2 face=arial>$data[1]</td>
		     <td><font size=2 face=arial>$data[2]</td>
		     <td><font size=2 face=arial>$data[3]</td>
		     <td><font size=2 face=arial>$data[4]</td></tr>";
      
   }

fclose($handle);
Thanks for your help!
- Jeff


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Last edited by ibanez270dx on Fri Jan 04, 2008 7:55 pm, edited 1 time in total.
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

add

Code: Select all

if($row==1){
   $row++;
   continue;
}
to the top of your while loop
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Post by alex.barylski »

Call fgetcsv() once before the loop and just swallow the line - ignore it whatever.
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

Hockey++

Less code FTW
ibanez270dx
Forum Commoner
Posts: 74
Joined: Thu Jul 27, 2006 12:06 pm
Location: Everywhere, California

Post by ibanez270dx »

Thanks! The if statement idea works perfectly!

- Jeff
Post Reply