Show CSV in Dadatables with php
Show CSV in Dadatables with php
zerano
Posts: 2Questions: 1Answers: 0
Hi,
I've a CSV table, which I want to print as datatable. But the system does not recognize the header (as manu header. It shows only the content)... I tried much different ways with the <thead> tag, but it does not work... Can anyone help?
<?php
$datei = 'example.csv';
echo '<table border="2" cellspacing="0" cellpadding="5" width="500" id="table_id" class="display">';
$open= fopen($datei, "r");
$zeile = 0;
while (($data = fgetcsv($open, 10000, ";"))) {
echo '<thead><tbody><tr>' . "\n";
for ( $x = 0; $x < count($data); $x++) {
if ($zeile == 0)
echo '<th>'.$data[$x].'</th></thead>' . "\n";
else
echo '<td>'.$data[$x].'</td>' . "\n";
}
$zeile++;
echo '</tr></tbody>'. "\n";
}
fclose($open);
echo '</table>';
?>
This discussion has been closed.
Answers
Ok, I resolved it: