title: Using PHP, read csv file, conditionally output to HTML
body: <p>I have a simple drop down box on a web page.  In it are all the states in the US.  When a user selects a state,
  I'd like to have a PHP script only return the companies that are in the state the user selected (as HTML).</p>
  
  <p>I've a csv file that reads as follows:</p>
  
  <blockquote>
    <p>stateId,company,contact,phone,when,addy1<br>
    3,abc mining,George,555-555-1234,june 6 2012,"Bronx,NY"<br>
    2,xyz mining,Fred,555-555-2345,june 7 2012,"Seattle,WA"<br>
    0,my company,Me,555-555-3456,june 8 2012,"Eugene,OR"<br>
    3,your company,You,555-555-4567,june 9 2012,"Bronx,NY"</p>
  </blockquote>
  
  <p>and on and on and on....</p>
  
  <p>Using the above, return via an HTML table, only the data (or lines in the csv) with a stateId = 3.</p>
  
  <p>So... I've seen many ways to use fgetcsv, but how would I accomplish the above problem?</p>
  
  <p>I was thinking you'd grab the selected index value of the drop-down, pass it as a conditional, iterate through each line, outputting only those with a state id of 3...  </p>
  
  <p>Ideally, I'd like to output them in a table, but a list or straight text will do.</p>
  
  <p>Being relatively new to PHP (it's been 10+ years since I've even looked at it...) - I'd REALLY appreciate the help.</p>
  
  <p>I know... a database would be easier - but I've complete control over the csv and would rather go this route for the time being.</p>
  
  <pre><code>    &lt;?php
  
  echo "&lt;table&gt;\n";
  
  $row = 0;
  $handle = fopen("mycsvfile.csv", "r");
  
  while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
      if ($row == 0) {
         // column line
          $num = count($data);
          echo "&lt;thead&gt;\n&lt;tr&gt;";
          $row++;
          for ($c=0; $c &lt; $num; $c++) {
              echo "&lt;th&gt;" . $data[$c] . "&lt;/th&gt;";
          }
          echo "&lt;/tr&gt;\n&lt;/thead&gt;\n\n&lt;tbody&gt;";
      } else {
          // non-header lines
          $num = count($data);
          echo "&lt;tr&gt;";
          $row++;
          for ($c=0; $c &lt; $num; $c++) {
              echo "&lt;td&gt;" . $data[$c] . "&lt;/td&gt;";
          }
          echo "&lt;/tr&gt;\n";
      }
  }
  fclose($handle);
  
  echo "&lt;/tbody&gt;\n&lt;/table&gt;";
  
  ?&gt;
  </code></pre>
  
  <p>I start to lose it after this point... This simply outputs all data - I still need it to show only data for the state the user selected, via a variable, and NOT output lines that are for other states not selected.</p>
  
  <p>Do I use strpos(), explode(), split()... I'm a dotNet programmer with little to no experience in php - and am hoping to learn.  This is my first project - so take it easy on me! I don't know and have not used php functions/methods - so I'm not familiar with them.  ;)</p>
  
  <p>I've XAMPP up and running, so I'm not completely hopeless.</p>