如何按列对此表进行排序 - 当我点击选择的标题(标题的名称将是链接)时,表格将按标题排序 - 列,在我的PHP中:
<?php
打开文本文件(第一行是标题除以;)
$fp = fopen('C:\...\usedlicences.txt','r') or die("can't open file");
创建带边框的表
echo "<table id='MyTable' border='1'>\n";
为包含标题的表创建标题行
echo "<td><b>id</b><td><b>name</b></td><td><b>surname</b></td><td><b>address</b></td><td><b>state</b></td><td><b>phone</b></td><td><b>city</b></td><td><b>date</b></td><td><b>color</b></td>";
$length = 1000;
$delimiter = ";";
$k=1;
从文件创建行并用数据填充它们(跳过第一个(标题)行)并添加第一列写入行的id
$csv_line = fgetcsv( $fp, $length, $delimiter);
while($csv_line = fgetcsv( $fp, $length, $delimiter ) ) {
echo "<tr>";
echo "<td>$k</td>";
$k++;
for ($i = 0, $j = count($csv_line); $i < $j; $i++) {
echo '<td>'.$csv_line[$i].'</td>';
}
}
echo "<tr>";
echo '</table>';
fclose($fp) or die("can't close file");
?>
显示警报使用了多少许可证(所有行减去标题行)
<script language="JavaScript">
var oRows = document.getElementById('MyTable').getElementsByTagName('tr');
var iRowCount = oRows.length-1;
alert('Licences used: ' + ((iRowCount)-1)+'!');
</script>
test.txt看起来像:
id;name;surname;address;state;phone;city;date;color
1;John;Simts;Yellow 12;Greenik;1234567;Mannds;12/3/1234;blue