2010-01-18 60 views
0

我一直在嘗試使用ajax排序一段時間,但表格根本無法排序。可能是什麼問題呢?我正在使用sorttable.js可排序是不是排序?

這是代碼我使用:

<script src="resources/sorttable.js" type="text/javascript"></script> 

      <!-- ON GOING --> 

      <div class="TabbedPanelsContent"> 
<div style="padding: 10px;"> 
<table width="100%" height="100%" border="0" cellpadding="5" cellspacing="0" class="sortable"> 

<b>Ongoing: <?php echo $totalRows_progress ?> </b> 

<p></p> 

<?php 
// Make a MySQL Connection 
mysql_select_db("speedycms") or die(mysql_error()); 

// Get all the data from the "example" table 
$result = mysql_query("SELECT * FROM tbl_accident WHERE progress='ongoing' ORDER BY id ASC") 
or die(mysql_error()); 

// Define $color=1 
$color="1"; 

echo ' 
<thead> 
<tr bgcolor="#cccccc"> 
<th width="45px" align="left">Case ID</th> 
<th width="90px" align="left">Solicitor/Case Ref</th> 
<th width="225px" align="left">Client Name/Address</th> 
<th width="70px" align="left">Accident Date</th> 
<th width="65px" align="left">Case Opened</th> 
<th width="55px" align="left">Total Days</th> 
<th width="55px" align="left"></th> 
</tr> 
</thead> 
'; 

while($rows=mysql_fetch_array($result)){ 

$caseOpen = date('d/m/Y', strtotime($rows['caseOpen'])); 
$caseOpen2 = date('Y-m-d', strtotime($rows['caseOpen'])); 

$days = (strtotime(date("Y-m-d")) - strtotime("$caseOpen2"))/(60 * 60 * 24); 

$days2 = round($days); 

// If $color==1 table row color = #FFC600 
if($color==1){ 
echo " 
<tbody> 
<tr bgcolor='#f2f2f2' valign='top'> 
<td>".$rows['id']."</td> 
<td>".$rows['currentSolicitor']."<BR>".$rows['caseReference']."</td> 
<td><a href='viewclient.php?id=".$rows['id']."' class=\"box\">" .$rows['clientName']."<BR> ".$rows['address']."</a></td> 
<td>".$rows['doaDay']."/".$rows['doaMonth']."/".$rows['doaYear']."</td> 
<td>".$caseOpen."</td> 
<td>".$days2."</td> 
<td> 
<a href='manageclient.php?id=".$rows['id']."' target='blank'><img src='resources/manage.png' border='0'></a><a href='viewclient.php?id=".$rows['id']."' target='blank'><img src='resources/view.png' border='0'></a><a href='editclient.php?id=".$rows['id']."' target='blank'><img src='resources/edit.png' border='0'></a><a href='printclient.php?id=".$rows['id']."' target='blank'><img src='resources/print.png' border='0'></a><a href='deleteclient.php?id=".$rows['id']."' target='blank'><img src='resources/no.png' border='0'></a> 
</td> 
</tr> 
</tbody> 
"; 
// Set $color==2, for switching to other color 
$color="2"; 
} 

// When $color not equal 1, use this table row color 
else { 
echo "<tbody> 
<tr bgcolor='#ffffff' valign='top'> 
<td>".$rows['id']."</td> 
<td>".$rows['currentSolicitor']."<BR>".$rows['caseReference']."</td> 
<td><a href='viewclient.php?id=".$rows['id']."' class=\"box\">" .$rows['clientName']."<BR> ".$rows['address']."</a></td> 
<td>".$rows['doaDay']."/".$rows['doaMonth']."/".$rows['doaYear']."</td> 
<td>".$caseOpen."</td> 
<td>".$days2."</td> 
<td> 
<a href='manageclient.php?id=".$rows['id']."' target='blank'><img src='resources/manage.png' border='0'></a><a href='viewclient.php?id=".$rows['id']."' target='blank'><img src='resources/view.png' border='0'></a><a href='editclient.php?id=".$rows['id']."' target='blank'><img src='resources/edit.png' border='0'></a><a href='printclient.php?id=".$rows['id']."' target='blank'><img src='resources/print.png' border='0'></a><a href='deleteclient.php?id=".$rows['id']."' target='blank'><img src='resources/no.png' border='0'></a> 
</td> 
</tr></tbody>"; 
// Set $color back to 1 
$color="1"; 
} 

} 
echo '<tfoot> 
<tr> 
<td></td> 
</tr> 
</tfoot>'; 
?> 
+0

你用螢火檢查發現sorttable.js實際上是裝的? – 2010-01-18 09:19:05

+0

這樣的檢查已完成...我刪除了thead,tbody和tfoot標記以修復它:) – methuselah 2010-01-19 05:40:42

回答

1

設法找到一個解決方案

<?php 
// Make a MySQL Connection 
mysql_select_db("speedycms") or die(mysql_error()); 

// Get all the data from the "example" table 
$result = mysql_query("SELECT * FROM tbl_accident WHERE progress='ongoing' ORDER BY id ASC") 
or die(mysql_error()); 

// Define $color=1 
$color="1"; 

echo ' 
<tr bgcolor="#cccccc"> 
<th width="45px" align="left">Case ID</th> 
<th width="90px" align="left">Solicitor/Case Ref</th> 
<th width="225px" align="left">Client Name/Address</th> 
<th width="70px" align="left">Accident Date</th> 
<th width="65px" align="left">Case Opened</th> 
<th width="55px" align="left">Total Days</th> 
<th width="55px" align="left"></th> 
</tr> 
'; 

while($rows=mysql_fetch_array($result)){ 

$caseOpen = date('d/m/Y', strtotime($rows['caseOpen'])); 
$caseOpen2 = date('Y-m-d', strtotime($rows['caseOpen'])); 

$days = (strtotime(date("Y-m-d")) - strtotime("$caseOpen2"))/(60 * 60 * 24); 

$days2 = round($days); 

// If $color==1 table row color = #FFC600 
if($color==1){ 
echo " 
<tr bgcolor='#f2f2f2' valign='top'> 
<td>".$rows['id']."</td> 
<td>".$rows['currentSolicitor']."<BR>".$rows['caseReference']."</td> 
<td><a href='viewclient.php?id=".$rows['id']."' class=\"box\">" .$rows['clientName']."<BR> ".$rows['address']."</a></td> 
<td>".$rows['doaDay']."/".$rows['doaMonth']."/".$rows['doaYear']."</td> 
<td>".$caseOpen."</td> 
<td>".$days2."</td> 
<td> 
<a href='manageclient.php?id=".$rows['id']."' target='blank'><img src='resources/manage.png' border='0'></a><a href='viewclient.php?id=".$rows['id']."' target='blank'><img src='resources/view.png' border='0'></a><a href='editclient.php?id=".$rows['id']."' target='blank'><img src='resources/edit.png' border='0'></a><a href='printclient.php?id=".$rows['id']."' target='blank'><img src='resources/print.png' border='0'></a><a href='deleteclient.php?id=".$rows['id']."' target='blank'><img src='resources/no.png' border='0'></a> 
</td> 
</tr> 
"; 
// Set $color==2, for switching to other color 
$color="2"; 
} 

// When $color not equal 1, use this table row color 
else { 
echo " 
<tr bgcolor='#ffffff' valign='top'> 
<td>".$rows['id']."</td> 
<td>".$rows['currentSolicitor']."<BR>".$rows['caseReference']."</td> 
<td><a href='viewclient.php?id=".$rows['id']."' class=\"box\">" .$rows['clientName']."<BR> ".$rows['address']."</a></td> 
<td>".$rows['doaDay']."/".$rows['doaMonth']."/".$rows['doaYear']."</td> 
<td>".$caseOpen."</td> 
<td>".$days2."</td> 
<td> 
<a href='manageclient.php?id=".$rows['id']."' target='blank'><img src='resources/manage.png' border='0'></a><a href='viewclient.php?id=".$rows['id']."' target='blank'><img src='resources/view.png' border='0'></a><a href='editclient.php?id=".$rows['id']."' target='blank'><img src='resources/edit.png' border='0'></a><a href='printclient.php?id=".$rows['id']."' target='blank'><img src='resources/print.png' border='0'></a><a href='deleteclient.php?id=".$rows['id']."' target='blank'><img src='resources/no.png' border='0'></a> 
</td> 
</tr>"; 
// Set $color back to 1 
$color="1"; 
} 

} 
echo ''; 
?> 
+1

更好地發佈差異(與您的問題相比),以便其他人可以看到您已更改的內容以更輕鬆地修復它。 – Veger 2010-01-18 10:21:11

+0

我刪除了thead,tbody和tfoot標籤:) – methuselah 2010-01-19 05:39:47