Directory Sorting Problem.

 
Post new topic   Reply to topic    Aprelium Forum Index -> PHP
View previous topic :: View next topic  
Author Message
TRUSTAbyss
-


Joined: 29 Oct 2003
Posts: 3752
Location: USA, GA

PostPosted: Sun Mar 26, 2006 9:08 am    Post subject: Directory Sorting Problem. Reply with quote

Hi,

This is really for Aprelium to read, or for those who are very advanced with
PHP. I've tried everything, but I cannot seem to make my custom directory
listing sort and output the correct results. Does anyone know how to sort a
directory listing the correct way? Here's the code I'm testing.

Code:
<pre>
<?php
/* Change Abyss's Directory string into an Array */

$lines = explode("\n", $_POST['files']);
 
/* Loop through the entire Array and create more Arrays
   such as name, url, size, date, and type */

for ($b=0; $b < count($lines); $b++)  {

  $array = explode("\t", $lines[$b]);

  $name[] = $array[0];
  $url[] = $array[1];
  $size[] = $array[2];
  $date[] = $array[3];
  $type[] = $array[4];

}

/* Create a multi-dimensional Array */

$dir = array($name, $url, $size, $date, $type);


/* Sort different parts of the array based on the parameters
    given, such as SORT_ASC/SORT_DESC. Output when done */

   array_multisort($dir[0], SORT_ASC,
                         $dir[1], SORT_ASC,
                         $dir[2], SORT_DESC,
                         $dir[3], SORT_ASC,
                         $dir[4], SORT_ASC);
 
print_r($dir);
?>
</pre>


Note: You must set this script as "Custom Script" under Directory Listing
of your Abyss Web Server console to test the output. The script will list a
structure of an array and show the results from Size DESCENDING. Now if
you look at it, the sizes aren't really ordered correctly.

I've tried everything, including SORT_NUMERIC on the size array and
nothing works. Can someone here, help me sort this problem out? :/

Example Output:
http://www.trustabyss.com/sort_output.txt

Sincerely, TRUSTpunk
Back to top View user's profile Send private message Visit poster's website
richardyork
-


Joined: 22 Jun 2004
Posts: 411
Location: United Kingdom

PostPosted: Sun Mar 26, 2006 11:54 am    Post subject: Reply with quote

Maybe a silly question, would some files be bytes and some kilobytes?

Slap me on the wrist if I'm totally off!! LOL
_________________
Please SEARCH the forums BEFORE asking questions!
Back to top View user's profile Send private message
AbyssUnderground
-


Joined: 31 Dec 2004
Posts: 3855

PostPosted: Sun Mar 26, 2006 12:20 pm    Post subject: Reply with quote

richardyork wrote:
Maybe a silly question, would some files be bytes and some kilobytes?

Slap me on the wrist if I'm totally off!! LOL


Thats a very valid point. If some files are displayed in bytes, kilobytes, megabytes etc, then they would not arrange in order. Youd have to temporaly convert them to bytes to get them to arrange properly.
_________________
Andy (AbyssUnderground) (previously The Inquisitor)
www.abyssunderground.co.uk
Back to top View user's profile Send private message Visit poster's website
aprelium
-


Joined: 22 Mar 2002
Posts: 6800

PostPosted: Sun Mar 26, 2006 12:22 pm    Post subject: Re: Directory Sorting Problem. Reply with quote

TRUSTpunk,

We have added another column to the table which acts as a key for the other columns. This column should always included in the array_multisort as a last parameters to help maintain the cohesion between the rows.

In your example, you were having too many sorting parameters. That's why the results were so confusing. Below you'll find a slightly modified version which does the numeric sorting on the size column only and it works fine.

Code:
<pre>
<?php
/* Change Abyss's Directory string into an Array */

$lines = explode("\n", $_POST['files']);
 
/* Loop through the entire Array and create more Arrays
   such as name, url, size, date, and type */

for ($b=0; $b < count($lines); $b++)  {

  $array = explode("\t", $lines[$b]);

  $id[] = $b;
  $name[] = $array[0];
  $url[] = $array[1];
  $size[] = $array[2];
  $date[] = $array[3];
  $type[] = $array[4];

}

/* Create a multi-dimensional Array */

$dir = array($name, $url, $size, $date, $type, $id);


/* Sort different parts of the array based on the parameters
    given, such as SORT_ASC/SORT_DESC. Output when done */

   array_multisort($dir[2], SORT_NUMERIC, SORT_DESC,
                         $dir[1],
                         $dir[0],
                         $dir[3],
                         $dir[4],
                         $dir[5]);
 
print_r($dir);
?>
</pre>

_________________
Support Team
Aprelium - http://www.aprelium.com
Back to top View user's profile Send private message Send e-mail
TRUSTAbyss
-


Joined: 29 Oct 2003
Posts: 3752
Location: USA, GA

PostPosted: Sun Mar 26, 2006 11:06 pm    Post subject: Reply with quote

Thank you so much! :-)

Edit: Original text causes problems so it's removed


Last edited by TRUSTAbyss on Mon Mar 27, 2006 1:10 am; edited 2 times in total
Back to top View user's profile Send private message Visit poster's website
MonkeyNation
-


Joined: 05 Feb 2005
Posts: 921
Location: Cardiff

PostPosted: Sun Mar 26, 2006 11:31 pm    Post subject: Reply with quote

TRUSTpunk wrote:
I'm very glad that I've finally stolen Apache's listing. They deserve it!


And just what is it they did to 'deserve it'?
"THEY'RE MORE POPULAR, MOTHERFUCKERS! IT'S ON NOW - I'M GOING TO STEAL ALL THEIR IDEAS". It's ridiculous.
_________________
Back to top View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger ICQ Number
AbyssUnderground
-


Joined: 31 Dec 2004
Posts: 3855

PostPosted: Sun Mar 26, 2006 11:33 pm    Post subject: Reply with quote

Maybe because he hates them? Im not a fan of Apache but I dont totally hate them...
_________________
Andy (AbyssUnderground) (previously The Inquisitor)
www.abyssunderground.co.uk
Back to top View user's profile Send private message Visit poster's website
TRUSTAbyss
-


Joined: 29 Oct 2003
Posts: 3752
Location: USA, GA

PostPosted: Mon Mar 27, 2006 12:56 am    Post subject: Reply with quote

Edit: Text Deleted

Last edited by TRUSTAbyss on Mon Mar 27, 2006 1:06 am; edited 3 times in total
Back to top View user's profile Send private message Visit poster's website
MonkeyNation
-


Joined: 05 Feb 2005
Posts: 921
Location: Cardiff

PostPosted: Mon Mar 27, 2006 1:01 am    Post subject: Reply with quote

TRUSTpunk wrote:
Correct! Also watch your language MonkeyNation. Why did I have a feeling
that an apache user on this forum was going to flame me for this lol?


There's nothing wrong with it, you just made such a childish comment afterward it needed criticism.
No one is flaming you, you are just apparantly inturpretting it as flaming since you realize yourself what a stupid comment it was.

I doubt I'm the only one here that cringed when they read that, either.
_________________
Back to top View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger ICQ Number
TRUSTAbyss
-


Joined: 29 Oct 2003
Posts: 3752
Location: USA, GA

PostPosted: Mon Mar 27, 2006 1:04 am    Post subject: Reply with quote

I removed my childish comments. I apologize, MonkeyNation for the dumb
comments made about stealing apache's Directory Listing. This won't go on
anymore. Aprelium can even delete the topic now if they want.

Sorry, that I offended anyone in this forum. LateR!
Back to top View user's profile Send private message Visit poster's website
AbyssUnderground
-


Joined: 31 Dec 2004
Posts: 3855

PostPosted: Mon Mar 27, 2006 7:42 am    Post subject: Reply with quote

I doubt anyone cared about what you said Josh, just some people like a rant and a rave about something...
_________________
Andy (AbyssUnderground) (previously The Inquisitor)
www.abyssunderground.co.uk
Back to top View user's profile Send private message Visit poster's website
loloyd
-


Joined: 03 Mar 2006
Posts: 435
Location: Philippines

PostPosted: Thu Jun 08, 2006 7:36 am    Post subject: Reply with quote

This is not a PHP script but I'm sorta spamming the board about how to go about setting up a sortable directoty listing using a JavaScript route.

For the benefit of forum browsers, I have now resorted to using JavaScript for sorting directory lists. See the full story at http://www.aprelium.com/forum/viewtopic.php?t=8872
and then test it in action at
http://home.loloyd.com/webttachments/.

Thanks.
_________________

http://home.loloyd.com/ is online if the logo graphic at left is showing.
Back to top View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Aprelium Forum Index -> PHP All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB phpBB Group