0

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
  • if any error shows in Your script.. Commented Mar 6, 2015 at 12:16
  • No I don't see an error @ABIRAMAN Commented Mar 6, 2015 at 12:29

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

4 Comments

Cannot use mysql order by command because last column is created at runtime and is not part of the database.
Also, if you need to use jquery: stackoverflow.com/questions/10543618/…
I tried the method in the link you mentioned. Its a life saver. Thanks a ton buddy. Voting you up! :)
@AbhishekSingh, you might also like to be aware of the jQuery plugin Tablesorter - make sure you use Mottie's fork. The original by Christian Bach hasn't been updated in years and is very rudimentary (and buggy) compared to the fork.
0

First Multi Dimensional create an array with your Mysql data and push Your last column value in that array. After that You can sort with that array in any language. And if you change that array to JSON you can easily sort with JQUERY

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.