Connecting Tech Pros Worldwide Help | Site Map

Read from 2nd line of CSV file

Newbie
 
Join Date: Mar 2008
Posts: 20
#1: Mar 4 '08
Hi,

I was working on a questionnaire. the answers to the questionnaire are stored in a csv file which acts as my database. Now i am trying to retrieve the data from the file into a table. However i want to start reading from the 2nd row of the file but am not being able to do so.
the code is like this:
[php]$rowcount = 0;
while(!feof($in))
{
$rowcount = $rowcount + 1;
$row = fgets($in);
if(strlen($row) == 0)
continue;
$rowarray = explode(",",$row);

print("<tr class=\"");

if($rowcount % 2)
print("oddRow");
else
print("evenRow");
print("\">");.
fclose($in)
}[/php]any help will be appreciated.

Thanks

Please enclose any code within the proper code tags. See the Posting Guidelines on how to do that. = moderator
ronverdonk's Avatar
Moderator
 
Join Date: Jul 2006
Location: The Netherlands
Posts: 4,139
#2: Mar 4 '08

re: Read from 2nd line of CSV file


Welcome to The Scripts!

Do you mean like this? Just test bthe row counter and ignore when 1[php] while(!feof($in))
{
$rowcount++;
$row = fgets($in);
if ($rowcount == 1)
continue;
if(strlen($row) == 0)
continue;
$rowarray = explode(",",$row);
}[/php]Ronald
Newbie
 
Join Date: Mar 2008
Posts: 20
#3: Mar 4 '08

re: Read from 2nd line of CSV file


Quote:

Originally Posted by ronverdonk

Welcome to The Scripts!

Do you mean like this? Just test bthe row counter and ignore when 1[php] while(!feof($in))
{
$rowcount++;
$row = fgets($in);
if ($rowcount == 1)
continue;
if(strlen($row) == 0)
continue;
$rowarray = explode(",",$row);
}[/php]Ronald


Yup it worked.. Thanks a lot.. Had been trying all sorts of things...Thank you..
ronverdonk's Avatar
Moderator
 
Join Date: Jul 2006
Location: The Netherlands
Posts: 4,139
#4: Mar 4 '08

re: Read from 2nd line of CSV file


You are welcome. See you around next time.

Ronald
Reply