Goulash
Goulash

Reputation: 3838

Ordering HTML tables without Javascript?

I have a table with numerical values as the first column, however it is totally unordered :( I was wondering if there is a way to order the rows (highest number at the top) without using JavaScript?

Here is some code that maybe helpful on how I get the data:

$dh = opendir( $dirname ) or die("couldn't open directory");
$start = isset($_GET['start']) ? (intval($_GET['start'])-1)*$bl_anzeige : 0;
while ( $file = readdir( $dh ) ) {
if ($file{0} != '.') {
  $xzal=$i++;
  if($xzal>= $start && $xzal<$start+$pps2) {
  $filecrc = str_replace(".txt","",$file);
  $filesize = filesize("./storage/". $filecrc);
  $filesize = ($filesize / 1048576);
  $fh = fopen ("./files/".$file, r);
  $filedata= explode('|', fgets($fh));
<tr><td class="filelist" align=center bgcolor=#F9F9F9><?php echo $filedata[11];?></td>

Upvotes: 0

Views: 6925

Answers (3)

Carsten
Carsten

Reputation: 18446

Instead of printing each row out directly, save all rows together into an array and then use one of PHP's many array sorting functions.

Upvotes: 4

Matthew Strawbridge
Matthew Strawbridge

Reputation: 20610

If you're talking about sorting a table in a static HTML page, many HTML editors have this feature. Or you could round-trip it to Excel.

Upvotes: 0

zzzzBov
zzzzBov

Reputation: 179046

Yes, you can sort the data via a server-side script.

If you want it live-sortable to a user without passing through a webserver, then you'll have to rely on JavaScript.

Upvotes: 3

Related Questions