Skip to content

Instantly share code, notes, and snippets.

@jasonglisson
Last active September 14, 2017 12:41
Show Gist options
  • Save jasonglisson/420d393e7cb32f71939b to your computer and use it in GitHub Desktop.
Save jasonglisson/420d393e7cb32f71939b to your computer and use it in GitHub Desktop.
Render table in PHP
$rows = 1;
if (($handle = fopen("<path to csv file>", "r")) !== FALSE) {
echo '<table class="table table-bordered toggle-square-filled default breakpoint footable">';
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
$num = count($data);
if ($rows == 1) {
echo '<thead><tr>';
} else {
echo '<tr>';
}
for ($c=0; $c < $num; $c++) {
//echo $data[$c] . "<br />\n";
if(empty($data[$c])) {
$value = "&nbsp;";
} else {
$value = $data[$c];
}
if ($rows == 1) {
echo '<th>'.$value.'</th>';
} else {
echo '<td>'.$value.'</td>';
}
}
if ($rows == 1) {
echo '</tr></thead><tbody>';
} else {
echo '</tr>';
}
$rows++;
}
echo '</tbody></table>';
fclose($handle);
} else {
echo '<h4>No CSV file found</h4>';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment