0

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>
2
  • If you are using a server-side language (which seems to be the case, judging by the comments in the answers), please say at least which one you are using and tag the question appropriately. Commented Nov 30, 2011 at 23:41
  • @Pekka, he had 0% when I mentioned how to review. He's a new user, so it was worth mentioning. I thought I was being polite, but out of context I can see how it might come off as brusque. Commented Nov 30, 2011 at 23:58

3 Answers 3

4

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.

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

Comments

3

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.

3 Comments

Nope i don't want it to be live I want it to be already sorted when the page loads :)
Any idea how to sort the data as it is grabbed from a series of text files
@King, I'm not a mind reader, I understand you're new to the Stack Overflow community, so I'd like you to also review the faq. You'll need to post some code and provide a more details to your question, otherwise I wont be able to help you.
0

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.

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.