title: Traversing through CSV file in PHP
body: <p>I have this code :</p>
  
  <pre><code>&lt;?php
     $handle = fopen("GeneratePicklist.csv", "r");
     $data = fgetcsv($handle, 5000, ",");
  ?&gt;
  </code></pre>
  
  <p>Which opens up a php file and converts it into a php array. Then I will list out the array contents and display them into a formatted page. I have this code and it's working.</p>
  
  <pre><code>&lt;?php
      echo "&lt;table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\"&gt;
          &lt;tr&gt;
              &lt;td class=\"dataHeader\" width=\"100\"&gt;Mat.Loc.&lt;/td&gt;
              &lt;td class=\"dataHeader\" width=\"20\"&gt;Qty&lt;/td&gt;
              &lt;td class=\"dataHeader\"&gt;Description&lt;/td&gt;
              &lt;td class=\"dataHeader\" width=\"150\"&gt;Part Number&lt;/td&gt;
              &lt;td class=\"dataHeader\" width=\"30\"&gt;Multiplier&lt;/td&gt;
              &lt;td class=\"dataHeader\" width=\"80\"&gt;Total Qty&lt;/td&gt;
          &lt;/tr&gt;
  ";
  $locatePartNoString = array_search("Part Number",$data);
  $arrayStart = $locatePartNoString-1;
  end($data);
  $lastField = key($data);
  $counter = ($lastField - $arrayStart);
  $arrayBegin = $locatePartNoString+6;
  while($counter&gt;0) {
      echo "
          &lt;tr&gt;
              &lt;td class=\"centered\"&gt;&lt;span class=\"title\"&gt;*".$data[$arrayBegin+4]."*&lt;/span&gt;&lt;br&gt;".$data[$arrayBegin+4]."&lt;/td&gt;
              &lt;td id=\"qty".$counter."\" class=\"centered\"&gt;".$data[$arrayBegin+1]."&lt;/td&gt;
              &lt;td&gt;".$data[$arrayBegin+2]."&lt;/td&gt;
              &lt;td class=\"centered\"&gt;".$data[$arrayBegin]."&lt;/td&gt;
              &lt;td class=\"centered\"&gt;&lt;input type=\"text\" id=\"multiplier".$counter."\" name=\"multiplier".$counter."\" value=\"1\" size=\"3\" style=\"border:1px dotted #CCC;\"&gt;&lt;/td&gt;
              &lt;td class=\"centered\"&gt;&lt;input type=\"text\" id=\"total".$counter."\" name=\"total".$counter."\" value=\"1\" size=\"3\" style=\"border:1px dotted #CCC;\"&gt;&lt;/td&gt;
          &lt;/tr&gt;
  
      ";
      $counter--;
  }
  echo "&lt;/table&gt;";
  ?&gt;
  </code></pre>
  
  <p>What I am trying to do is the traverse through the CSV file and select certain data only within the coverage of <code>$arrayBegin</code> variable and the last part of my CSV data. I have done the first line and its working good but I do not know how to increment so my pointer moves to the next line of the CSV file and do the same formula as my first line of data.</p>
  
  <p>Here's a sample of the CSV content, 7 fields:</p>
  
  <pre><code>ÊÊ,Part Number,Qty,Description,BB Type,Material Location,Serial Number
  ÊÊ,013224-001,1,"PCA,DDR2-800,MINIDIMM MOD256MBx 40",BOM,ASSY,ID121608ZS
  ÊÊ,122657-00A,1,SOFTWARE TEST (US M3 CTO),BOM,ASSY,
  ÊÊ,376383-002,8,"ASSY, BLANK,SFF",BOM,ASSY,
  ÊÊ,458943-003,1,"CA ASSY, SFP BATTERY, 15 POS, 28AWG, 24",BOM,ASSY,
  ÊÊ,460499-001,1,"ASSY, 4/V650HT BATTERY CHARGER MODULE",BOM,ASSY,
  ÊÊ,499256-001,2,"ASSY, BLANK,MEDIA BAY,ML350G6",BOM,ASSY,
  ÊÊ,500203-061,2,"DIMM,4GB PC3-10600R,256Mx4,RoHS",BOM,ASSY,RAKWF8DXV2Q100
  </code></pre>
  
  <p>I just need to select certain data from each line and then move on to the next line. How do i traverse to the next line using my while loop? Thank you for your future responses.</p>