Displaying a CSV file as an HTML table in a CRUD page

Posted on

Problem

<?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 '<tr>';
echo "<td>$type</td>";
echo "<td>$site_name</td>";
echo "<td>$site_address</td>";
echo "<td>$contact_no</td>";
echo "<td>$customer_no</td>";
echo "<td>$details</td>";
echo "<td>$email</td>";
echo "<td>$phone</td>";
echo "<td>$tech</td>";
echo "<td><a class="btn btn-warning"" href=""./?p=form_edit_band&

Solution

band=$i"">

<

i class=""icon-edit icon-white"">

<

/i>

Leave a Reply

Your email address will not be published. Required fields are marked *