I am generating an HTML table from a CSV file using the following code.
I'd like to only display columns with the following indexes:
$idsColumnsWanted = array(0,1,19,16);
How do I work this into my existing code?
echo "<table class='table table-bordered'>\n\n";
$f = fopen("users.csv", "r");
$first_line=false;
while (($line = fgetcsv($f)) !== false) {
$row ="";
if($first_line == false) {
$row = "<thead><tr>";
$col= "th";
}
else {
$row = "<tr>";
$col= "td";
}
$is_empty = false;
foreach ($line as $cell) {
if ($cell !== '') {
$row .= "<".$col.">" . htmlspecialchars($cell) . "</".$col.">";
} else {
$is_empty = true;
}
}
if($first_line == false) $row .= "</tr></thead>";
else $row .= "</tr>";
$first_line=true;
if ($is_empty) {
continue;
} else {
echo $row;
}
}
fclose($f);
echo "\n</table>";