我有一个从 postgres 查询生成的 PHP 表。如何使用 tablesorter 插件在表的开头插入带有编号行的索引列?排序工作。谢谢你。
克雷格克雷
qwef
<html>
<head>
<link href="/media/css/blue/style.css" rel="stylesheet">
<script src="/media/js/jquery.js" type="text/javascript"></script>
<script src="/media/js/jquery.tablesorter.js" type="text/javascript"></script>
<script src="/media/js/jquery.tablesorter.widgets.js" type="text/javascript"> </script>
<script src="/media/js/jquery.tablesorter.pager.js" type="text/javascript"></script>
<script type="text/javascript">
$(function(){
$("#tabel").tablesorter({ widgets: [ 'zebra' , 'filter' ] })
});
</script>
</head>
<body>
<?php
$con = pg_connect("user=* password=* host=localhost port=5432 dbname=users ") or die (pg_last_error());
$query = "SELECT * from users";
$result = pg_query($con, $query);
echo "<table id=\"tabel\" class=\"tablesorter\">
<thead>
<tr>";
//next code get column names
for($i=0; $i < pg_num_fields($result); $i++){
$field_info = pg_field_name($result, $i);
echo "<th> $field_info </th>";
}
echo "
</tr>
</thead>";
//next code fetch cells content
echo "<tbody>";
while ($row=pg_fetch_row($result)){
echo "<tr>";
foreach($row as $_column){
echo "<td> $_column </td>";
}
echo "</tr>";
}
echo "</tbody>
</table>";
pg_close($con);
?>
</body>
</html>