View previous topic :: View next topic |
Author |
Message |
TRUSTAbyss -
Joined: 29 Oct 2003 Posts: 3752 Location: USA, GA
|
Posted: Sun Mar 26, 2006 9:08 am Post subject: Directory Sorting Problem. |
|
|
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 |
|
 |
richardyork -
Joined: 22 Jun 2004 Posts: 411 Location: United Kingdom
|
Posted: Sun Mar 26, 2006 11:54 am Post subject: |
|
|
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 |
|
 |
AbyssUnderground -
Joined: 31 Dec 2004 Posts: 3855
|
Posted: Sun Mar 26, 2006 12:20 pm Post subject: |
|
|
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 |
|
 |
aprelium -
Joined: 22 Mar 2002 Posts: 6800
|
Posted: Sun Mar 26, 2006 12:22 pm Post subject: Re: Directory Sorting Problem. |
|
|
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 |
|
 |
TRUSTAbyss -
Joined: 29 Oct 2003 Posts: 3752 Location: USA, GA
|
Posted: Sun Mar 26, 2006 11:06 pm Post subject: |
|
|
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 |
|
 |
MonkeyNation -
Joined: 05 Feb 2005 Posts: 921 Location: Cardiff
|
Posted: Sun Mar 26, 2006 11:31 pm Post subject: |
|
|
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 |
 |
 |
AbyssUnderground -
Joined: 31 Dec 2004 Posts: 3855
|
Posted: Sun Mar 26, 2006 11:33 pm Post subject: |
|
|
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 |
|
 |
TRUSTAbyss -
Joined: 29 Oct 2003 Posts: 3752 Location: USA, GA
|
Posted: Mon Mar 27, 2006 12:56 am Post subject: |
|
|
Edit: Text Deleted
Last edited by TRUSTAbyss on Mon Mar 27, 2006 1:06 am; edited 3 times in total |
|
Back to top |
|
 |
MonkeyNation -
Joined: 05 Feb 2005 Posts: 921 Location: Cardiff
|
Posted: Mon Mar 27, 2006 1:01 am Post subject: |
|
|
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 |
 |
 |
TRUSTAbyss -
Joined: 29 Oct 2003 Posts: 3752 Location: USA, GA
|
Posted: Mon Mar 27, 2006 1:04 am Post subject: |
|
|
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 |
|
 |
AbyssUnderground -
Joined: 31 Dec 2004 Posts: 3855
|
Posted: Mon Mar 27, 2006 7:42 am Post subject: |
|
|
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 |
|
 |
loloyd -
Joined: 03 Mar 2006 Posts: 435 Location: Philippines
|
|
Back to top |
|
 |
|