Displaying a CSV file as an HTML table in a CRUD page &lt;?php 
            // Read all lines of the CSV file into an array
            // The "file" function in PHP returns an array of all the lines in the file listed
            $lines = file('passes.csv',FILE_IGNORE_NEW_LINES);

            // Counter variable for line number
            $i = 0;

            //Iterate over the array of lines
            foreach($lines as $line) {
                $parts = explode(',',$line);
                $type = $parts[0];
                $site_name = $parts[1];
                $site_address = $parts[2];
                $contact_no = $parts[3];
                $customer_no = $parts[4];
                $details = $parts[5];
                $email = $parts[6];
                $phone = $parts[7];
                $tech = $parts[8];
                echo '&lt;tr&gt;';
                echo    "&lt;td&gt;$type&lt;/td&gt;";
                echo    "&lt;td&gt;$site_name&lt;/td&gt;";
                echo    "&lt;td&gt;$site_address&lt;/td&gt;";
                echo    "&lt;td&gt;$contact_no&lt;/td&gt;";
                echo    "&lt;td&gt;$customer_no&lt;/td&gt;";
                echo    "&lt;td&gt;$details&lt;/td&gt;";
                echo    "&lt;td&gt;$email&lt;/td&gt;";
                echo    "&lt;td&gt;$phone&lt;/td&gt;";
                echo    "&lt;td&gt;$tech&lt;/td&gt;";
                echo    "&lt;td&gt;&lt;a class=\"btn btn-warning\" href=\"./?p=form_edit_band&amp;band=$i\"&gt;&lt;i class=\"icon-edit icon-white\"&gt;&lt;/i&gt;&lt;/a&gt; &lt;a class=\"btn btn-danger\" href=\"actions/delete_band.php?linenum=$i\"&gt;&lt;i class=\"icon-trash icon-white\"&gt;&lt;/i&gt;&lt;/a&gt;&lt;/td&gt;";
                echo '&lt;/tr&gt;';

                $i++; // increment line number
            }
            ?&gt;


This is slow. also it would be awesome if someone could tell me how to do this dynamically with different csv file.
The biggest problem with this code is not so much the CSV formatting, but the fact that you have a "Delete" link like this:

&lt;a class="btn btn-danger" href="actions/delete_band.php?linenum=$i"&gt;

The fact that a deletion can be triggered by an HTTP GET request exposes you to a Spider of Doom situation:


  Things went pretty well for a few days after going live. But, on day six, things went not-so-well: all of the content on the website had completely vanished and all pages led to the default "please enter content" page. […]
  
  A user [had] copied and pasted some content from one page to another, including an "edit" hyperlink to edit the content on the page. Normally, this wouldn't be an issue, since an outside user would need to enter a name and password. But, the CMS authentication subsystem didn't take into account the sophisticated hacking techniques of Google's spider. Whoops.


Moreover, GET requests are generally cacheable, so clicking on the link might not reliably cause the row to be deleted.

For requests that trigger a state change on the server, what you want is an HTTP POST.  POSTs are not cacheable, and will not be triggered by web crawlers.  To change the link to perform a POST, you could either make it a button in a form or do something using JavaScript.