我试图使用TableSorter来排序...我使用PHP放入表中的数据,但它似乎并没有起作用。通过各种其他类似的帖子,但仍然无法用我的代码找到错误:
<!DOCTYPE html>
<html>
<head>
<title>PHP Test</title>
<link rel="stylesheet" href="css/style.css" type="text/css">
<script type="text/javasrcipt" src="js/jquery-latest.js"></script>
<script type="text/javascript" src="js/jquery.tablesorter.js"></script>
<script type="text/javascript">
$(document).ready(function(){ $("#summary").tablesorter(); });
</script>
</head>
<body>
<?PHP
$user_name = "root";
$password = "";
$database = "test_db";
$server = "127.0.0.1";
$db_handle = mysql_connect($server, $user_name, $password);
$db_found = mysql_select_db($database, $db_handle);
if ($db_found) {
$SQL = "SELECT * FROM picks_returned WHERE `pickID` < 48";
$result = mysql_query($SQL);
echo "<table id='summary' class='tablesorter'>
<thead>
<tr>
<th>PickID</th>
<th>Date</th>
<th>Sport</th>
<th>Match</th>
<th>Pick</th>
<th>Odds</th>
<th>Risked</th>
<th>Grade</th>
<th>Returned</th>
</tr>
</thead>
<tbody>\n";
while ( $db_field = mysql_fetch_assoc($result) ) {
echo "<tr>\n";
echo "<td>" . $db_field['pickID'] . "</td>\n";
echo "<td>" . $db_field['date'] . "</td>\n";
echo "<td>" . $db_field['sport'] . "</td>\n";
echo "<td>" . $db_field['matchup'] . "</td>\n";
echo "<td>" . $db_field['pick'] . "</td>\n";
echo "<td>" . $db_field['odds'] . "</td>\n";
echo "<td>" . $db_field['risked'] . "</td>\n";
echo "<td>" . $db_field['grade'] . "</td>\n";
echo "<td>" . ROUND($db_field['returned'],4) . "</td>\n";
echo "</tr>\n";
}
echo "</tbody>
</table>\n";
mysql_close($db_handle);
}
else {
print "Database NOT Found ";
}
?>
</body>
</html>
生成的HTML示例如下:
<!DOCTYPE html>
<html>
<head>
<title>PHP Test</title>
<link rel="stylesheet" href="css/style.css" type="text/css">
<script type="text/javasrcipt" src="js/jquery-latest.js"></script>
<script type="text/javascript" src="js/jquery.tablesorter.js"></script>
<script type="text/javascript">
$(document).ready(function(){ $("#summary").tablesorter(); });
</script>
</head>
<body>
<table id='summary' class='tablesorter'>
<thead>
<tr>
<th>PickID</th>
<th>Date</th>
<th>Sport</th>
<th>Match</th>
<th>Pick</th>
<th>Odds</th>
<th>Risked</th>
<th>Grade</th>
<th>Returned</th>
</tr>
</thead>
<tbody>
<tr>
<td>45</td>
<td>2013-01-02</td>
<td>NCAAB</td>
<td>Boise St - Texas Arlington</td>
<td>Boise St -3.5</td>
<td>1.91</td>
<td>8</td>
<td>W</td>
<td>7.28</td>
</tr>
<tr>
<td>46</td>
<td>2013-01-02</td>
<td>NCAAB</td>
<td>Davidson - Duke</td>
<td>Davidson +12.5</td>
<td>1.91</td>
<td>8</td>
<td>L</td>
<td>-8</td>
</tr>
<tr>
<td>47</td>
<td>2013-01-03</td>
<td>NCAAB</td>
<td>South Dakota St - UMKC</td>
<td>South Dakota St -9</td>
<td>1.91</td>
<td>8</td>
<td>W</td>
<td>7.28</td>
</tr>
</tbody>
</table>
</body>
</html>