gpt4 book ai didi

php - 使用 Jquery 进行表排序

转载 作者:行者123 更新时间:2023-11-29 07:41:43 24 4
gpt4 key购买 nike

我已经尝试了其他线程的所有解决方案,但似乎没有任何对我有用。我试图显示权重分数递减的表格(这是我表格的最后一列)。

我编写了以下代码,该代码不适用于 PHP 提供的表格,但可以完美地处理 html 页面。

查看源代码:http://hidden.com/diversefund.php

它起作用的html页面:http://hidden.com/new.html

我正在使用数据库提供的表,所以这是一个问题。

我的 php 脚本中的重要代码行:

<style>
#form {
border: 5px solid violet;
}
input[type=submit] {padding:5px 15px; background:white; border:1px solid blue;
cursor:pointer;
-webkit-border-radius: 5px;
border-radius: 5px; }
</style>

<script type='text/javascript' src='http://code.jquery.com/jquery-compat-git.js'></script>

<script type='text/javascript' src='//code.jquery.com/jquery-1.9.1.js'></script>


<link rel="stylesheet" type="text/css" href="/css/result-light.css">

<script type='text/javascript'>
$(window).load(function(){
var $tbody = $('table tbody');
$tbody.find('tr').sort(function (a, b) {
var tda = parseFloat($(a).find('td:eq(7)').text()); //the column to sort by
var tdb = parseFloat($(b).find('td:eq(7)').text()); //the column to sort by
// if a < b return 1
return tda < tdb ? 1
// else if a > b return -1
:
tda > tdb ? -1
// else they are equal - return 0
:
0;
}).appendTo($tbody);
}); </script>

$queryx1 = mysql_query("select * from analytics_divequ where aum >= '$aum1' AND fiveyr >= '$fiveyr1' AND oneyr >= '$lastyr1' ", $linkx);
echo '<table cellpadding="5" border="1px" align="center" id="caltbl"><thead><tr><th><b>Mutual Fund Scheme</b></th><th><b>AUM</b></th><th><b>Last Year %</b></th><th><b>Two Years %</b></th><th><b>Three Years %</b></th><th><b>5 Years %</b></th><th><b>Weight Score</b></th></tr></thead><tbody>';
$i=1;
while ($row2x = mysql_fetch_array($queryx1)) {
$mfsc=$row2x['mfscheme'];
$aum=$row2x['aum'];
$fiveyr=$row2x['fiveyr'];
$lastyr=$row2x['oneyr'];
$threeyr=$row2x['threeyr'];
$twoyr=$row2x['twoyr'];
$wscore=(($aum*$aumc1)+($fiveyr*$fiveyrc1)+($lastyr*$oneyrc1))/100;
?>
<tr><td><? echo $mfsc ?></td><td><? echo $aum ?></td><td><? echo $lastyr ?></td><td><? echo $twoyr ?></td><td><? echo $threeyr ?></td><td><? echo $fiveyr ?></td><td class="sortnr"><? echo $wscore ?></td></tr>

echo '</tbody></table> <br>';
?>

还要补充一点,我不能在这里使用 Mysql,因为你可以看到最后一列不是数据库的一部分。

最佳答案

可以使用插件吗?

或者 PHP 来做你需要做的事情?如果数据存储在数据库中,您可以使用“ORDER BY”使用不同的 MySQL 语句完成所需的任务。或者创建一个新的 PHP 数组,该数组将按正确的顺序包含数据,然后使用循环显示数据。 (http://php.net/manual/en/function.usort.php)

对于表管理(排序、搜索等),我建议使用数据表( https://datatables.net )。从上次我搜索起,这是市场上最好的表 jquery 插件...但是,根据我的经验,数据表无法处理大量数据,一旦你有 1000 多行,可能需要 10-20 秒要加载的页面。

关于php - 使用 Jquery 进行表排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28898409/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com