0
我目前有一個填充mysql數據的表,我有一些jQuery代碼來分頁數據。這工作正常,但是,我也使用jquery.tablesorter.min.js排序表。這隻適用於第一頁,只要您更改頁面,它只會對該頁面上的數據進行排序,而不是將所有數據拖入表格中。我需要能夠單擊列標題的時候,不只是通過下面的分頁代碼解析頁面上的數據進行排序的所有數據:使用mysql數據對分頁表進行排序
的tablesorter:
<script>
$(document).ready(function() {
$("#sortedtable").tablesorter({ sortlist: [0,0] });
});
</script>
分頁:
<script type="text/javascript">
$(document).ready(function() {
//Declaring Variables
var page = 1;
var per_page = 20;
var items = $('.row').length;
var page_last = Math.ceil(items/per_page);
//Set Page
function setPage(page) {
$('.row').slice(0, page * per_page).hide();
$('.row').slice(page * per_page - per_page, page * per_page).show();
$('.row').slice(page * per_page).hide();
$('#page_display').html('Page ' + page + ' of ' + page_last);
}
//Next Button
$('.next').click(function() {
if (page < page_last) {
page++;
setPage(page);
}
});
//Previous Button
$('.prev').click(function() {
if (page > 1) {
page--;
setPage(page);
}
});
setPage(1);
});
</script>
PHP/MySQL的
$cbsql = "SELECT patient_id, AES_DECRYPT(firstName,'$key') as firstName, AES_DECRYPT(lastName,'$key') as lastName, AES_DECRYPT(telephone1,'$key') as telephone1, AES_DECRYPT(email,'$key') as email, cbdate, status, owner FROM patientprofiles WHERE owner = '$owner' and cbdate <= '$today' AND cbdate != 0000-00-00 ORDER BY cbdate ASC";
$mycbData = mysql_query($cbsql,$con);
echo "<table id=sortedtable>
<thead>\n<tr>
<th>Date</th>
<th>Patient</th>
<th>Phone</th>
<th>Email</th>
</tr>\n</thead>\n";
while($record=mysql_fetch_array($mycbData)){
$mysql_cbdate = date('m/d/Y', strtotime($record['cbdate']));
echo "<tr class=row>";
echo "<td>" .$mysql_cbdate. "</td>";
echo "<td>" . stripslashes($record['lastName']) . ", " .$record['firstName'] . "</td>";
echo "<td>" .$record['telephone1']. "</td>";
echo "<td>" .$record['email']. "</td>";
echo "</tr>";
}
echo "</table>";
?>
聲明我知道我應該用mysql來完成,我會盡快完成這個項目
請,或不使用'mysql_ *'功能(http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in -php)。 *他們不再維護,並[已正式棄用](https://wiki.php.net/rfc/mysql_deprecation)*。看到[紅色框](http://uk.php.net/manual/en/function.mysql-connect.php)?學習[準備的語句](http://en.wikipedia.org/wiki/Prepared_statement),並使用[PDO](http://us1.php.net/pdo)或[MySQLi](http:// us1.php.net/mysqli)。 [這篇文章](http://php.net/manual/en/mysqlinfo.api.choosing.php)將幫助你決定哪些。 – 2014-10-06 16:14:43