2013-08-28 168 views
-2

該表被diplayed正常,但無法排序。 這兩個.js文件都與.php文件本身位於同一個目錄中。jQuery tablesorter不工作

<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> 
+1

' 「#tabel」'應該是拼寫表 –

+2

$(「#tabel」)< - 錯字! – Paddyd

+2

錯別字,它*確實*匹配表本身的id。不是問題。 –

回答

3

給這一個鏡頭:

$t .= '<thead><tr>'; 
//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 .= '</tr></thead>'; 

我基本上包裹着你的<th>的在<tr>,都會響起的例子代碼在這裏:http://tablesorter.com/docs/

+0

它的工作原理...我可以在哪裏放置

來分選鋼材... – wwwglro

+0

對不起,我不太明白。您想做什麼? – Floris

+0

我希望信息顯示在帶有邊框的表格中... – wwwglro