I am using the following code to create a HTML table from a CSV file. How can I make this table sortable? I tried using Jquery tablesorter but the problem seems to be that when I click on a row to sort it, that it gets recreated by the PHP afterwards which results in an unsorted table.
<!DOCTYPE html>
<html>
<?php
function jj_readcsv($filename, $header=false) {
$handle = fopen($filename, "r");
echo '<table>';
//display header row if true
if ($header) {
$csvcontents = fgetcsv($handle);
echo '<tr>';
foreach ($csvcontents as $headercolumn) {
echo "<th>$headercolumn</th>";
}
echo '</tr>';
}
// displaying contents
while ($csvcontents = fgetcsv($handle)) {
echo '<tr>';
foreach ($csvcontents as $column) {
echo "<td>$column</td>";
}
echo '</tr>';
}
echo '</table>';
fclose($handle);
}
jj_readcsv('table.csv',true);
?>