How to make sorting like this: jQuery plugin for sorting HTML tables ?

The fact is that this method does not work, since my data is not ready (not written), but is output from MySQL

 <?php ob_start("ob_gzhandler"); define('INCLUDE_CHECK',true); include($_SERVER['DOCUMENT_ROOT'].'/connect.php'); //$result = mysql_query("SELECT * FROM `applications` ORDER BY `id`") or die(mysql_error()); $result = mysql_query(" SELECT `devices`.*, `selects`.deviceName AS name_device, `divisions`.divisionName AS divisionName FROM `devices` LEFT JOIN `selects` ON `selects`.id = `devices`.name_device LEFT JOIN `divisions` ON `divisions`.id = `devices`.division ORDER BY `devices`.id") or die(mysql_error()); $text = ' <table border="1" style="width:100%;" class="table table-condensed table-bordered table-hover"> <thead> <tr> <!--th style="text-align:center;" width="1%">№</th--> <th style="text-align:center;" width="1%;" vertical-align="middle";>Наименование</th> <th style="text-align:center;" width="8%">Сетевое имя</th> <th style="text-align:center;" width="6%">IP</th> <th style="text-align:center;" width="3%">Кабинет</th> <th style="text-align:center;" width="3%">Отдел</th> <th style="text-align:center;" width="18%">Спецификация</th> <th style="text-align:center;" width="5%">Пользователи</th> <th style="text-align:center;" width="9%">Серийный номер</th> <th style="text-align:center;" width="8%">Инвентарный номер</th> <th style="text-align:center;" width="1%"><input type="checkbox" id="selall" value="1" class="checkbox"></th> </tr> </thead>'; while($row = mysql_fetch_assoc($result)) { $text .= ' <tbody> <tr> <!--td>'.$row['id'].'</td--> <td>'.$row['name_device'].'</td> <td>'.$row['netname'].'</td> <td>'.$row['ip'].'</td> <td>'.$row['room'].'</td> <td>'.$row['divisionName'].'</td> <td>'.$row['cp'].", ".$row['motherboard'].", ".$row['ram'].", ".$row['hdd'].", ".$row['vga'].", ".$row['dvd'].", ".$row['corpus'].'</td> <td>'.$row['users'].'</td> <td>'.$row['serial_number'].'</td> <td>'.$row['invent_number'].'</td> <td><input type="checkbox" class="checkbox" value="" name="ip[]"></td> </tr> </tbody>'; } $text .= ''; $text = str_replace('1900-01-01','<span style="color:blue">Не выдан</span>',$text); echo $text; //Закрываем соединение @mysql_close($result); ?> 
  • Religion does not allow you to make a selection of MySQL, which further wrap in html code as in the example? - Sharp - eyed
  • And I wrote everything that is unclear? How to make a selection from MySQL or wrap it in html code? - Sharp - eyed
  • I already have a sample of all the fields and data from MySQL and turns into HTML - Nicolayka
  • The code in the studio - Sharp - eyed
  • Added code - Nicolayka

1 answer 1

Insert jquery-latest.js and jquery.tablesorter.js , add id for the table, for example, <table border="1" style="width:100%;" class="table table-condensed table-bordered table-hover" id="myTable"> <table border="1" style="width:100%;" class="table table-condensed table-bordered table-hover" id="myTable"> the <tbody> and </tbody> must be removed from the while .
And add to echo "<tbody>$text</tbody>"; and it will work.