title: Import specific rows and columns form csv file into table using php
body: <p>I'm very new to php but have been experimenting fairly successfully with using 'fgetcsv' to bring in a CSV file and convert it into an html table. </p>
  
  <p>However I also have a large CSV file with 70 columns and 700 rows, but I only want to display columns 1 to 47 and rows 3 to 21 in one table, and then same columns but rows 22 to 44 in another table.</p>
  
  <p>I'd appreciate some help with this, below is the code I am currently using:</p>
  
  <pre><code>&lt;?php
  
  $row = 1;
  if (($handle = fopen("CSV/test.csv", "r")) !== FALSE) {
  
      echo '&lt;table border="1"&gt;';
  
      while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
          $num = count($data);
          if ($row == 1) {
              echo '&lt;thead&gt;&lt;tr&gt;';
          }else{
              echo '&lt;tr&gt;';
          }
  
          for ($c=0; $c &lt; $num; $c++) {
              //echo $data[$c] . "&lt;br /&gt;\n";
              if(empty($data[$c])) {
                 $value = "&amp;nbsp;";
              }else{
                 $value = $data[$c];
              }
              if ($row == 1) {
                  echo '&lt;th&gt;'.$value.'&lt;/th&gt;';
              }else{
                  echo '&lt;td&gt;'.$value.'&lt;/td&gt;';
              }
          }
  
          if ($row == 1) {
              echo '&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;';
          }else{
              echo '&lt;/tr&gt;';
          }
          $row++;
      }
  
      echo '&lt;/tbody&gt;&lt;/table&gt;';
      fclose($handle);
  }
  ?&gt;
  </code></pre>