methuselah methuselah - 5 months ago 14
jQuery Question

sortable is not sorting?

I've been trying to sort a table using ajax for sometime now but the table doesn't sort at all. What could be the problem?

I'm using sorttable.js.

This is the code I'm using:

<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>';
?>

Answer

managed to find a solution

<?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 '';
?>