我一直在尝试使用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 :(得分: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 '';
?>