该表显示正常,但无法对其进行排序。这两个 .js 文件与 .php 文件本身位于同一目录中。
<html>
<head>
<script src="jquery-1.6.2.js" type="text/javascript"></script>
<script src="jquery.tablesorter.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
$("#tabel").tablesorter();
});
</script>
</head>
<body>
<?php
$con = pg_connect("user=bct password=bct host=localhost port=5432 dbname=users ") or die (pg_last_error());
$query = "SELECT * from users";
$result = pg_query($con, $query);
$t = '<table id="tabel" class="tablesorter">';
$t .= '<thead>';
//next code get column names
for($i=0; $i < pg_num_fields($result); $i++){
$field_info = pg_field_name($result, $i);
$t .= '<th>' . $field_info . '</th>';
}
$t .= '</thead>';
//next code fetch cell content
$t .= '<tbody>';
while ($row=pg_fetch_row($result)){
$t .= '<tr>';
foreach($row as $_column){
$t .= '<td>' .$_column. '</td>';
$temp=$row;
}
$t .= '</tr>';
}
$t .= '</tbody></table>';
echo $t;
pg_close($con);
?>
</body>
</html>