Page 1 of 1

[SOLVED] Quick Question...

Posted: Fri Jan 04, 2008 4:21 pm
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]

Posted: Fri Jan 04, 2008 4:37 pm
by Kieran Huggins
add

Code: Select all

if($row==1){
   $row++;
   continue;
}
to the top of your while loop

Posted: Fri Jan 04, 2008 4:59 pm
by alex.barylski
Call fgetcsv() once before the loop and just swallow the line - ignore it whatever.

Posted: Fri Jan 04, 2008 5:00 pm
by Kieran Huggins
Hockey++

Less code FTW

Posted: Fri Jan 04, 2008 5:04 pm
by ibanez270dx
Thanks! The if statement idea works perfectly!

- Jeff