Read from 2nd line of CSV file

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • learnPHP
    New Member
    • Mar 2008
    • 20

    #1

    Read from 2nd line of CSV file

    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(",",$ro w);

    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
    Last edited by ronverdonk; Mar 4 '08, 06:58 PM. Reason: code within tags!!
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #2
    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(",",$ro w);
    }[/php]Ronald

    Comment

    • learnPHP
      New Member
      • Mar 2008
      • 20

      #3
      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(",",$ro w);
      }[/php]Ronald

      Yup it worked.. Thanks a lot.. Had been trying all sorts of things...Thank you..

      Comment

      • ronverdonk
        Recognized Expert Specialist
        • Jul 2006
        • 4259

        #4
        You are welcome. See you around next time.

        Ronald

        Comment

        Working...