dongyanju0945 2015-03-06 12:04
浏览 27
已采纳

表与Jquery排序

I have tried all the solutions from other threads but nothing seems to work for me. I am trying to show the table with descending Weight Score (which is the last column of my table).

I have written the following code which doesn't work with PHP provided table but works perfectly with html page.

view-source:http://hidden.com/diversefund.php

The html page where it does work: http://hidden.com/new.html

I am working with database provided table so this is a problem.

Important lines of code from my php script:

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

Also to add I can't use Mysql here, as you can see the last column is not part of the database.

  • 写回答

2条回答 默认 最新

  • duanjizi9443 2015-03-06 12:21
    关注

    Can you use plugin?

    Or PHP to do what you need to? You can accomplish required task with different MySQL statement, using "ORDER BY", if data stored in the database.. or create a new PHP array that will contain data in correct order and than display data using a loop. (http://php.net/manual/en/function.usort.php)

    For table management (sorting, search and so on) I would recommend using datatables (https://datatables.net). From last time i was searching around this was the best jquery plugin for tables on the market... However, in my experience datatables can't handle a lot of data, once you have 1000+ rows it may take 10-20 second for page to load.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题